dialysis_api_controller.go 472KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307
  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. var first_sup int64
  1771. if first_super == "是" {
  1772. first_sup = 1
  1773. }
  1774. if first_super == "否" {
  1775. first_sup = 2
  1776. }
  1777. if first_super == "请选择" {
  1778. first_sup = 0
  1779. }
  1780. is_sequential := c.GetString("is_sequential")
  1781. var is_sequent int64
  1782. if is_sequential == "是" {
  1783. is_sequent = 1
  1784. }
  1785. if is_sequential == "否" {
  1786. is_sequent = 2
  1787. }
  1788. if is_sequential == "请选择" {
  1789. is_sequent = 0
  1790. }
  1791. conduct := c.GetString("conduct")
  1792. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1793. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1794. //
  1795. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1796. // if appRole.UserType == 3 {
  1797. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1798. // if getPermissionErr != nil {
  1799. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1800. // return
  1801. // } else if headNursePermission == nil {
  1802. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1803. // return
  1804. // }
  1805. // }
  1806. //}
  1807. // 查询信息规挡的设置天数
  1808. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1809. if infor.ID > 0 && infor.WeekDay > 0 {
  1810. var cha_time int64
  1811. timeNowStr := time.Now().Format("2006-01-02")
  1812. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1813. //今日的日期减去设置的日期
  1814. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1815. if cha_time >= recordDate.Unix() {
  1816. //查询审核是否允许
  1817. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1818. //申请状态不允许的情况 拒绝修改
  1819. if infor.ApplicationStatus != 1 {
  1820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1821. return
  1822. }
  1823. }
  1824. }
  1825. if mode_id > 0 {
  1826. var str string
  1827. //查找该机构用的是什么透析器
  1828. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1829. if filedConfig.ID > 0 {
  1830. str = dialyzerPerfusionApparatus
  1831. } else {
  1832. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1833. }
  1834. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1835. }
  1836. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1837. var dialysis_dialyszers_id int64
  1838. var dialysis_strainer_id int64
  1839. var dialysis_irrigation_id int64
  1840. if len(goodList) > 0 {
  1841. for _, item := range goodList {
  1842. if item.SpecificationName == dialysis_dialyszers {
  1843. dialysis_dialyszers_id = item.ID
  1844. }
  1845. if item.SpecificationName == dialysis_irrigation {
  1846. dialysis_irrigation_id = item.ID
  1847. }
  1848. if item.SpecificationName == dialysis_strainer {
  1849. dialysis_strainer_id = item.ID
  1850. }
  1851. }
  1852. }
  1853. //TODO 需要根据角色去判断
  1854. prescription := models.DialysisPrescription{
  1855. UserOrgId: adminUserInfo.Org.Id,
  1856. PatientId: id,
  1857. RecordDate: recordDate.Unix(),
  1858. ModeId: mode_id,
  1859. DialysisDuration: dialysis_duration,
  1860. Dialyzer: dialyzer,
  1861. PerfusionApparatus: perfusion_apparatus,
  1862. BloodFlowVolume: blood_flow_volume,
  1863. DewaterAmount: dewater_amount,
  1864. DisplaceLiqui: displace_liqui,
  1865. ReplacementWay: replacement_way,
  1866. Anticoagulant: anticoagulant,
  1867. AnticoagulantShouji: anticoagulant_shouji,
  1868. AnticoagulantWeichi: anticoagulant_weichi,
  1869. AnticoagulantZongliang: anticoagulant_zongliang,
  1870. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1871. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1872. Kalium: kalium,
  1873. Sodium: sodium,
  1874. Calcium: calcium,
  1875. Bicarbonate: bicarbonate,
  1876. Glucose: glucose,
  1877. // DryWeight: dry_weight,
  1878. DialysateFlow: dialysate_flow,
  1879. DialysateTemperature: dialysate_temperature,
  1880. // PrescriptionDoctor: prescription_doctor,
  1881. ReplacementTotal: replacement_total,
  1882. Conductivity: conductivity,
  1883. Remark: remark,
  1884. Status: 1,
  1885. CreatedTime: time.Now().Unix(),
  1886. UpdatedTime: time.Now().Unix(),
  1887. DialysisDurationMinute: dialysisDurationMinute,
  1888. DialysisDurationHour: dialysisDurationHour,
  1889. TargetUltrafiltration: targetUltrafiltration,
  1890. DialysateFormulation: dialysateFormulation,
  1891. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1892. BodyFluid: body_fluid,
  1893. SpecialMedicine: special_medicine,
  1894. SpecialMedicineOther: special_medicine_other,
  1895. DisplaceLiquiPart: displace_liqui_part,
  1896. DisplaceLiquiValue: displace_liqui_value,
  1897. BloodAccess: blood_access,
  1898. Ultrafiltration: ultrafiltration,
  1899. BodyFluidOther: body_fluid_other,
  1900. Niprocart: niprocart,
  1901. Jms: jms,
  1902. FistulaNeedleSet: fistula_needle_set,
  1903. FistulaNeedleSet16: fistula_needle_set_16,
  1904. Hemoperfusion: hemoperfusion,
  1905. DialyserSterilised: dialyser_sterilised,
  1906. Filtryzer: filtryzer,
  1907. Dialyzers: dialyzers,
  1908. Injector: injector,
  1909. Bloodlines: bloodlines,
  1910. TubingHemodialysis: tubing_hemodialysis,
  1911. Package: safe_package,
  1912. ALiquid: a_liquid,
  1913. TargetKtv: target_ktv,
  1914. PreImpulse: pre_impulse,
  1915. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1916. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1917. Blood: blood,
  1918. DialysisDialyszers: dialysis_dialyszers,
  1919. DialysisIrrigation: dialysis_irrigation,
  1920. AntioxidantCommodityName: antioxidant_commodity_name,
  1921. DisplaceSpeed: displace_speed,
  1922. Illness: illness,
  1923. Amylaceum: amylaceum,
  1924. SingleTime: single_time,
  1925. SingleWater: single_water,
  1926. ReplacementFlow: replacement_flow,
  1927. PlasmaSeparator: plasma_separator,
  1928. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1929. OxygenUptake: oxygen_uptake,
  1930. OxygenFlow: oxygen_flow,
  1931. OxygenTime: oxygen_time,
  1932. HemodialysisPipelines: hemodialysis_pipelines,
  1933. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1934. PunctureNeedle: puncture_needle,
  1935. PunctureNeedleCount: puncture_needle_count,
  1936. Epo: epo,
  1937. EpoCount: epo_count,
  1938. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1939. AdminUserId: admin_user_id,
  1940. IsWater: is_war,
  1941. DrhyWater: drhy_water,
  1942. DryWaterHour: dry_water_hour,
  1943. WaterMachine: water_machine,
  1944. AddAmount: add_amount,
  1945. ReduceAmount: reduce_amount,
  1946. DialysisRemark: dialysis_remark,
  1947. PrescribingNumber: prescribing_number,
  1948. StartSodium: start_sodium,
  1949. SodiumCurve: sodium_curve,
  1950. TreatmentRemark: treatment_remark,
  1951. PrescriptionSodium: prescription_sodium,
  1952. DialysisFluidFlow: dialysis_fluid_flow,
  1953. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1954. PrescriptionWater: prescription_water,
  1955. DialysisStrainer: dialysis_strainer,
  1956. Chaptalization: chaptalization,
  1957. WashingTime: washing_time,
  1958. WarshCount: warsh_count,
  1959. BloodAccessPartId: blood_access_part_id,
  1960. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1961. Dialyzate: dialyzate,
  1962. DialysisDialyszersId: dialysis_dialyszers_id,
  1963. DialysisIrrigationId: dialysis_irrigation_id,
  1964. DialysisStrainerId: dialysis_strainer_id,
  1965. FirstSuper: first_sup,
  1966. IsSequential: is_sequent,
  1967. Conduct: conduct,
  1968. }
  1969. if adminUserInfo.Org.Id == 10721 {
  1970. if prescription.ModeId == 2 {
  1971. if prescription.ReplacementTotal == 0 {
  1972. prescription.ReplacementTotal = 15
  1973. }
  1974. }
  1975. }
  1976. //查询最近透析准备表里是否存在 透析器 灌流器
  1977. //
  1978. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1979. //
  1980. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1981. //
  1982. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1983. //if len(mation)>0{
  1984. // for _, item := range splitStr {
  1985. // for _,it := range mation{
  1986. // if(item == it.SpecificationName){
  1987. //
  1988. // //查询最近一次的透析器
  1989. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1990. //
  1991. // if errcode == gorm.ErrRecordNotFound{
  1992. // //插入数据
  1993. // prepare := models.DialysisBeforePrepare{
  1994. // UserOrgId: adminUserInfo.Org.Id,
  1995. // PatientId: id,
  1996. // RecordDate: recordDate.Unix(),
  1997. // GoodTypeId: it.GoodTypeId,
  1998. // GoodId: it.ID,
  1999. // Count: 1,
  2000. // Ctime: time.Now().Unix(),
  2001. // Creater: adminUserInfo.AdminUser.Id,
  2002. // Status:1,
  2003. //
  2004. // }
  2005. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2006. // fmt.Println("",errcode)
  2007. // }
  2008. // }
  2009. // }
  2010. //
  2011. // }
  2012. //
  2013. // for _, item := range splitIrrigation {
  2014. // for _,it := range mation{
  2015. // if(item == it.SpecificationName){
  2016. // //查询最近一次的透析器
  2017. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2018. // if errcode == gorm.ErrRecordNotFound{
  2019. // //插入数据
  2020. // prepare := models.DialysisBeforePrepare{
  2021. // UserOrgId: adminUserInfo.Org.Id,
  2022. // PatientId: id,
  2023. // RecordDate: recordDate.Unix(),
  2024. // GoodTypeId: it.GoodTypeId,
  2025. // GoodId: it.ID,
  2026. // Count: 1,
  2027. // Ctime: time.Now().Unix(),
  2028. // Creater: adminUserInfo.AdminUser.Id,
  2029. // Status:1,
  2030. //
  2031. // }
  2032. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2033. // fmt.Println(errcode)
  2034. // }
  2035. // }
  2036. // }
  2037. // }
  2038. //}
  2039. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2040. if dialysisPrescription.ID == 0 { //新增
  2041. if appRole.UserType == 2 || appRole.UserType == 1 {
  2042. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2043. }
  2044. prescription.Creater = adminUserInfo.AdminUser.Id
  2045. //针对河间咸得
  2046. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2047. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2048. prescription.DisplaceLiquiPart = 0
  2049. prescription.DisplaceLiquiValue = 0
  2050. }
  2051. }
  2052. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2053. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2054. }
  2055. err := service.AddSigleRecord(&prescription)
  2056. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2057. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 || adminUserInfo.Org.Id == 10766 {
  2058. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2059. if len(monitorList) > 0 {
  2060. var ultrafiltration_rate float64
  2061. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2062. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2063. var replacement_rate float64
  2064. if adminUserInfo.Org.Id == 10721 {
  2065. //乘10 除10是为了保留一位小数
  2066. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2067. }
  2068. if adminUserInfo.Org.Id == 9478 {
  2069. //乘10 除10是为了保留一位小数
  2070. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2071. }
  2072. if adminUserInfo.Org.Id == 10766 {
  2073. //乘10 除10是为了保留一位小数
  2074. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2075. }
  2076. var firstOpeateTime = monitorList[0].OperateTime
  2077. for _, item := range monitorList {
  2078. //超滤率
  2079. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2080. //置换率
  2081. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2082. //超滤量
  2083. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2084. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2085. //置换量
  2086. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2087. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2088. }
  2089. }
  2090. }
  2091. //记录日志
  2092. byterequest, _ := json.Marshal(prescription)
  2093. prescriptionLog := models.XtDialysisPrescriptionLog{
  2094. UserOrgId: prescription.UserOrgId,
  2095. Ctime: time.Now().Unix(),
  2096. Mtime: 0,
  2097. ErrLog: string(byterequest),
  2098. AdminUserId: adminUserInfo.AdminUser.Id,
  2099. RecordDate: prescription.RecordDate,
  2100. PatientId: prescription.PatientId,
  2101. Source: "手机端新增保存处方",
  2102. Status: 1,
  2103. }
  2104. service.CreatePrescriptionLog(prescriptionLog)
  2105. finish := models.XtDialysisFinish{
  2106. IsFinish: 1,
  2107. UserOrgId: adminUserInfo.Org.Id,
  2108. Status: 1,
  2109. Ctime: time.Now().Unix(),
  2110. Mtime: 0,
  2111. Module: 1,
  2112. RecordDate: recordDate.Unix(),
  2113. Sourse: 1,
  2114. PatientId: id,
  2115. }
  2116. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2117. if dialysisFinish.ID == 0 {
  2118. service.CreateDialysisFinish(finish)
  2119. }
  2120. //长沙南雅医院,自动生成抗凝剂的临时处方
  2121. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2122. if prescribing_number == 0 {
  2123. prescribing_number = 1
  2124. }
  2125. if prescribing_number == 0 && id == 14682 {
  2126. prescribing_number = 2
  2127. }
  2128. if prescribing_number == 0 && id == 18560 {
  2129. prescribing_number = 2
  2130. }
  2131. advice := models.DoctorAdvice{
  2132. UserOrgId: adminUserInfo.Org.Id,
  2133. PatientId: id,
  2134. GroupNo: 0,
  2135. AdviceType: 2,
  2136. RecordDate: recordDate.Unix(),
  2137. AdviceDate: recordDate.Unix(),
  2138. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2139. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2140. AdviceDesc: "",
  2141. ReminderDate: 0,
  2142. SingleDose: anticoagulant_zongliang,
  2143. SingleDoseUnit: "iu",
  2144. DrugSpec: 0,
  2145. DrugSpecUnit: "",
  2146. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2147. PrescribingNumberUnit: "支",
  2148. DeliveryWay: "静脉注射",
  2149. ExecutionFrequency: "上机前",
  2150. AdviceDoctor: 0,
  2151. Status: 1,
  2152. CreatedTime: time.Now().Unix(),
  2153. UpdatedTime: time.Now().Unix(),
  2154. IsPrescription: 1,
  2155. ExecutionState: 2,
  2156. StopState: 2,
  2157. IsSettle: 2,
  2158. }
  2159. // 查询排班信息
  2160. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2161. if schedulePatient.ID > 0 {
  2162. if schedulePatient.ScheduleType == 1 {
  2163. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2164. }
  2165. if schedulePatient.ScheduleType == 2 {
  2166. advice.StartTime = recordDate.Unix() + 9*60*60
  2167. }
  2168. }
  2169. // 抗凝剂名称
  2170. switch anticoagulant {
  2171. case 1:
  2172. advice.AdviceName = "无肝素"
  2173. break
  2174. case 2:
  2175. advice.AdviceName = "普通肝素"
  2176. break
  2177. case 3:
  2178. advice.AdviceName = "低分子肝素"
  2179. break
  2180. case 4:
  2181. advice.AdviceName = "阿加曲班"
  2182. break
  2183. case 5:
  2184. advice.AdviceName = "枸橼酸钠"
  2185. break
  2186. case 6:
  2187. advice.AdviceName = "低分子肝素钙"
  2188. break
  2189. case 7:
  2190. advice.AdviceName = "低分子肝素钠"
  2191. break
  2192. case 8:
  2193. advice.AdviceName = "依诺肝素"
  2194. break
  2195. case 9:
  2196. advice.AdviceName = "达肝素"
  2197. break
  2198. case 10:
  2199. advice.AdviceName = "体外抗凝"
  2200. break
  2201. case 11:
  2202. advice.AdviceName = "那曲肝素"
  2203. break
  2204. case 12:
  2205. advice.AdviceName = "无抗凝剂"
  2206. break
  2207. }
  2208. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2209. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2210. advice.AdviceDoctor = appRole.AdminUserId
  2211. }
  2212. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2213. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2214. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2215. advice.AdviceName = "低分子肝素钠注射液"
  2216. // 修改患者临时医嘱里的抗凝剂医嘱
  2217. advice.ID = advicePrescription.ID
  2218. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2219. } else {
  2220. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2221. advice.AdviceName = "低分子肝素钠注射液"
  2222. // 新增患者临时医嘱里的抗凝剂医嘱
  2223. service.CreateDoctorAdvice(&advice)
  2224. }
  2225. }
  2226. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2227. redis := service.RedisClient()
  2228. defer redis.Close()
  2229. //清空key 值
  2230. redis.Set(key, "", time.Second)
  2231. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2232. redis.Set(keyOne, "", time.Second)
  2233. }
  2234. //获取key,清空redis
  2235. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2236. redis := service.RedisClient()
  2237. //清空key 值
  2238. redis.Set(key, "", time.Second)
  2239. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2240. //清空key 值
  2241. redis.Set(keyOne, "", time.Second)
  2242. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2243. //清空key 值
  2244. redis.Set(keyTwo, "", time.Second)
  2245. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2246. redis.Set(keySix, "", time.Second)
  2247. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2248. redis.Set(keySeven, "", time.Second)
  2249. if err == nil {
  2250. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2251. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2252. //清空key 值
  2253. redis.Set(keyThree, "", time.Second)
  2254. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2255. //清空key 值
  2256. redis.Set(keyFour, "", time.Second)
  2257. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2258. redis.Set(keyFive, "", time.Second)
  2259. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2260. redis.Set(keySix, "", time.Second)
  2261. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2262. redis.Set(keySeven, "", time.Second)
  2263. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2264. //清空key 值
  2265. redis.Set(keyOne, "", time.Second)
  2266. if updateErr != nil {
  2267. utils.ErrorLog("%v", updateErr)
  2268. }
  2269. defer redis.Close()
  2270. c.ServeSuccessJSON(map[string]interface{}{
  2271. "prescription": prescription,
  2272. })
  2273. }
  2274. } else { //修改
  2275. //if mode_id > 0 {
  2276. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2277. //}
  2278. //if template.TemplateId == 1 {
  2279. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2280. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2281. // if getPermissionErr != nil {
  2282. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2283. // return
  2284. // } else if headNursePermission == nil {
  2285. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2286. // return
  2287. // }
  2288. // }
  2289. //}
  2290. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2291. prescription.Modifier = adminUserInfo.AdminUser.Id
  2292. if appRole.UserType == 2 || appRole.UserType == 1 {
  2293. prescription_doctor := adminUserInfo.AdminUser.Id
  2294. prescription.PrescriptionDoctor = prescription_doctor
  2295. } else {
  2296. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2297. }
  2298. if dialysisPrescription.Creater == 0 { //体重称
  2299. prescription.Creater = adminUserInfo.AdminUser.Id
  2300. } else {
  2301. prescription.Creater = dialysisPrescription.Creater
  2302. if adminUserInfo.Org.Id == 9882 {
  2303. if appRole.UserType == 2 || appRole.UserType == 1 {
  2304. prescription_doctor := adminUserInfo.AdminUser.Id
  2305. prescription.PrescriptionDoctor = prescription_doctor
  2306. prescription.Creater = prescription_doctor
  2307. }
  2308. }
  2309. }
  2310. prescription.ID = dialysisPrescription.ID
  2311. if adminUserInfo.Org.Id == 10721 {
  2312. if prescription.ModeId == 2 {
  2313. if prescription.ReplacementTotal == 0 {
  2314. prescription.ReplacementTotal = 15
  2315. }
  2316. }
  2317. }
  2318. service.UpDateDialysisPrescription(&prescription)
  2319. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2320. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 || adminUserInfo.Org.Id == 10766 {
  2321. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2322. if len(monitorList) > 0 {
  2323. var ultrafiltration_rate float64
  2324. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2325. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2326. var replacement_rate float64
  2327. if adminUserInfo.Org.Id == 10721 {
  2328. //乘10 除10是为了保留一位小数
  2329. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2330. }
  2331. if adminUserInfo.Org.Id == 9478 || adminUserInfo.Org.Id == 10766 {
  2332. //乘10 除10是为了保留一位小数
  2333. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2334. }
  2335. var firstOpeateTime = monitorList[0].OperateTime
  2336. for _, item := range monitorList {
  2337. //超滤率
  2338. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2339. //置换率
  2340. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2341. //超滤量
  2342. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2343. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2344. //置换量
  2345. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2346. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2347. }
  2348. }
  2349. }
  2350. //记录日志
  2351. byterequest, _ := json.Marshal(prescription)
  2352. prescriptionLog := models.XtDialysisPrescriptionLog{
  2353. UserOrgId: prescription.UserOrgId,
  2354. Ctime: time.Now().Unix(),
  2355. Mtime: 0,
  2356. ErrLog: string(byterequest),
  2357. AdminUserId: adminUserInfo.AdminUser.Id,
  2358. RecordDate: prescription.RecordDate,
  2359. PatientId: prescription.PatientId,
  2360. Source: "手机端修改处方",
  2361. Status: 1,
  2362. }
  2363. service.CreatePrescriptionLog(prescriptionLog)
  2364. finish := models.XtDialysisFinish{
  2365. IsFinish: 1,
  2366. UserOrgId: adminUserInfo.Org.Id,
  2367. Status: 1,
  2368. Ctime: time.Now().Unix(),
  2369. Mtime: 0,
  2370. Module: 1,
  2371. RecordDate: recordDate.Unix(),
  2372. Sourse: 1,
  2373. PatientId: id,
  2374. }
  2375. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2376. if dialysisFinish.ID == 0 {
  2377. service.CreateDialysisFinish(finish)
  2378. }
  2379. //修改处方
  2380. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2381. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2382. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2383. if advicePrescription.ID > 0 {
  2384. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2385. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2386. redis := service.RedisClient()
  2387. defer redis.Close()
  2388. //清空key 值
  2389. redis.Set(key, "", time.Second)
  2390. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2391. redis.Set(keyOne, "", time.Second)
  2392. }
  2393. }
  2394. //获取key,清空redis
  2395. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2396. redis := service.RedisClient()
  2397. //清空key 值
  2398. redis.Set(key, "", time.Second)
  2399. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2400. //清空key 值
  2401. redis.Set(keyOne, "", time.Second)
  2402. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2403. redis.Set(keySix, "", time.Second)
  2404. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2405. redis.Set(keySeven, "", time.Second)
  2406. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2407. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2408. //清空key 值
  2409. redis.Set(keyTwoOne, "", time.Second)
  2410. defer redis.Close()
  2411. if updateErr != nil {
  2412. utils.ErrorLog("%v", updateErr)
  2413. }
  2414. c.ServeSuccessJSON(map[string]interface{}{
  2415. "prescription": prescription,
  2416. })
  2417. }
  2418. }
  2419. func (c *DialysisAPIController) Finish() {
  2420. id, _ := c.GetInt64("patient", 0)
  2421. recordDateStr := c.GetString("record_date")
  2422. nurseID, _ := c.GetInt64("nurse")
  2423. end_time := c.GetString("end_time")
  2424. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2425. internal_fistula := c.GetString("blood_access_internal_fistula")
  2426. catheter := c.GetString("catheter")
  2427. cruor := c.GetString("cruor")
  2428. mission := c.GetString("mission")
  2429. condenser := c.GetString("condenser")
  2430. if id <= 0 || nurseID <= 0 {
  2431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2432. return
  2433. }
  2434. adminUserInfo := c.GetMobileAdminUserInfo()
  2435. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2436. if patient.ID == 0 {
  2437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2438. return
  2439. }
  2440. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2441. if getNurseErr != nil {
  2442. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2444. return
  2445. } else if nurse == nil {
  2446. c.ErrorLog("护士不存在")
  2447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2448. return
  2449. }
  2450. if len(recordDateStr) == 0 {
  2451. recordDateStr = time.Now().Format("2006-01-02")
  2452. }
  2453. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2454. if parseDateErr != nil {
  2455. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2457. return
  2458. }
  2459. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2460. if parseEndDateErr != nil {
  2461. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2463. return
  2464. }
  2465. // 查询信息规挡的设置天数
  2466. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2467. if infor.ID > 0 && infor.WeekDay > 0 {
  2468. var cha_time int64
  2469. timeNowStr := time.Now().Format("2006-01-02")
  2470. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2471. //今日的日期减去设置的日期
  2472. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2473. if cha_time >= recordDate.Unix() {
  2474. //查询审核是否允许
  2475. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2476. //申请状态不允许的情况 拒绝修改
  2477. if infor.ApplicationStatus != 1 {
  2478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2479. return
  2480. }
  2481. }
  2482. }
  2483. //now := time.Now()
  2484. //year, month, day := now.Date()
  2485. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2486. //todayTimeStamp := today_time.Unix()
  2487. // 获取当天的第一条透析纪录
  2488. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2489. if getMonitorRecordsErr != nil {
  2490. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2492. return
  2493. }
  2494. // 获取当前的最后一条透析纪录
  2495. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2496. if getMonitorRecordsErr != nil {
  2497. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2499. return
  2500. }
  2501. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2502. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2503. if getAADErr != nil {
  2504. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2506. return
  2507. }
  2508. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2509. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2510. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2511. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2512. if assessmentAfterDislysis != nil {
  2513. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2514. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2515. } else {
  2516. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2517. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2518. tempassessmentAfterDislysis.Status = 1
  2519. tempassessmentAfterDislysis.PatientId = id
  2520. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2521. }
  2522. //长沙南雅
  2523. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2524. //获取最后一条透析处方数据
  2525. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2526. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2527. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2528. }
  2529. if dialysisOrder.Stage == 1 {
  2530. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2531. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2532. fmt.Println(value)
  2533. a, b := math.Modf(value)
  2534. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2535. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2536. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2537. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2538. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2539. }
  2540. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2541. //var num1 int64
  2542. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2543. //fmt.Println(num1)
  2544. //sub := float64(num1 / 3600)
  2545. //fmt.Println(sub)
  2546. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2547. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2548. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2549. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2550. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2551. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2552. if adminUserInfo.Org.Id != 10375 {
  2553. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2554. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2555. }
  2556. if adminUserInfo.Org.Id == 10766 {
  2557. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2558. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2559. }
  2560. if adminUserInfo.Org.Id != 10445 {
  2561. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2562. }
  2563. //北方营口医院
  2564. if adminUserInfo.Org.Id == 10445 {
  2565. //获取最后一条透析处方数据
  2566. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2567. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2568. } else {
  2569. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2570. }
  2571. //新化博翔
  2572. if adminUserInfo.Org.Id == 10447 {
  2573. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2574. }
  2575. //阳春
  2576. if adminUserInfo.Org.Id == 10485 {
  2577. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2578. }
  2579. if adminUserInfo.Org.Id == 10551 {
  2580. //获取最后一条透析处方数据
  2581. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2582. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2583. }
  2584. if adminUserInfo.Org.Id == 10580 {
  2585. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2586. }
  2587. if adminUserInfo.Org.Id == 10612 {
  2588. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2589. }
  2590. //孝康
  2591. if adminUserInfo.Org.Id == 10693 {
  2592. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2593. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2594. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2595. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2596. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2597. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2598. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2599. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2600. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2601. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2602. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2603. }
  2604. if adminUserInfo.Org.Id == 10721 {
  2605. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2606. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2607. }
  2608. if adminUserInfo.Org.Id == 10697 {
  2609. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2610. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2611. lastWeightAfter.LastAfterWeight = floatAfeter
  2612. }
  2613. if adminUserInfo.Org.Id == 10624 {
  2614. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2615. }
  2616. }
  2617. 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 {
  2618. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2619. if adminUserInfo.Org.Id != 10702 {
  2620. if evaluation.SystolicBloodPressure == 0 {
  2621. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2622. if adminUserInfo.Org.Id == 10693 {
  2623. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2624. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2625. }
  2626. pre := models.PredialysisEvaluation{
  2627. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2628. }
  2629. fmt.Println("prew", pre)
  2630. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2631. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2632. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2633. redis := service.RedisClient()
  2634. redis.Set(key, "", time.Second)
  2635. redis.Set(keyOne, "", time.Second)
  2636. defer redis.Close()
  2637. fmt.Println(getNurseErr)
  2638. }
  2639. }
  2640. if adminUserInfo.Org.Id != 10702 {
  2641. if evaluation.DiastolicBloodPressure == 0 {
  2642. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2643. if adminUserInfo.Org.Id == 10693 {
  2644. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2645. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2646. }
  2647. pres := models.PredialysisEvaluation{
  2648. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2649. }
  2650. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2651. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2652. redis := service.RedisClient()
  2653. redis.Set(key, "", time.Second)
  2654. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2655. redis.Set(keyOne, "", time.Second)
  2656. defer redis.Close()
  2657. fmt.Println(getNurseErr)
  2658. }
  2659. }
  2660. if adminUserInfo.Org.Id != 10702 {
  2661. if evaluation.PulseFrequency == 0 {
  2662. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2663. if adminUserInfo.Org.Id == 10693 {
  2664. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2665. evaluation.PulseFrequency = pulseFrequency
  2666. }
  2667. press := models.PredialysisEvaluation{
  2668. PulseFrequency: evaluation.PulseFrequency,
  2669. }
  2670. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2671. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2672. redis := service.RedisClient()
  2673. redis.Set(key, "", time.Second)
  2674. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2675. redis.Set(keyOne, "", time.Second)
  2676. defer redis.Close()
  2677. fmt.Println(getNurseErr)
  2678. }
  2679. }
  2680. if evaluation.Temperature == 0 {
  2681. evaluation.Temperature = fmonitorRecords.Temperature
  2682. press := models.PredialysisEvaluation{
  2683. Temperature: evaluation.Temperature,
  2684. }
  2685. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2686. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2687. redis := service.RedisClient()
  2688. redis.Set(key, "", time.Second)
  2689. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2690. redis.Set(keyOne, "", time.Second)
  2691. defer redis.Close()
  2692. fmt.Println(getNurseErr)
  2693. }
  2694. }
  2695. if adminUserInfo.Org.Id == 9583 {
  2696. //获取透析处方的最后一条数据
  2697. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2698. if diaerr != nil {
  2699. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2701. return
  2702. }
  2703. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2704. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2705. }
  2706. }
  2707. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2708. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2709. }
  2710. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2711. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2712. }
  2713. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2714. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2715. }
  2716. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10766 {
  2717. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2718. }
  2719. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2720. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2721. }
  2722. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2723. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2724. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2725. }
  2726. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2727. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2728. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2729. }
  2730. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2731. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2732. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2733. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2734. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2735. }
  2736. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10735 {
  2737. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2738. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2739. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2740. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2741. }
  2742. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10766 {
  2743. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2744. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2745. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2746. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2747. }
  2748. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2749. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2750. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2751. }
  2752. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2753. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2754. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2755. }
  2756. if lastAssessmentAfterDislysis != nil {
  2757. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2758. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2759. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2760. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2761. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2762. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2763. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2764. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2765. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2766. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2767. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2768. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2769. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2770. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2771. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2772. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2773. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2774. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2775. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2776. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2777. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2778. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2779. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2780. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2781. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2782. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2783. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2784. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2785. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2786. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2787. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2788. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2789. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2790. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2791. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2792. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2793. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2794. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2795. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2796. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2797. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2798. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2799. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2800. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2801. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2802. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2803. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2804. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2805. if tempassessmentAfterDislysis.PatientId == 18695 {
  2806. tempassessmentAfterDislysis.ActualDisplacement = 0
  2807. }
  2808. if adminUserInfo.Org.Id != 10375 {
  2809. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2810. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2811. }
  2812. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2813. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2814. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2815. }
  2816. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2817. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2818. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2819. }
  2820. }
  2821. finish := models.XtDialysisFinish{
  2822. IsFinish: 1,
  2823. UserOrgId: adminUserInfo.Org.Id,
  2824. Status: 1,
  2825. Ctime: time.Now().Unix(),
  2826. Mtime: 0,
  2827. Module: 9,
  2828. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2829. Sourse: 1,
  2830. PatientId: tempassessmentAfterDislysis.PatientId,
  2831. }
  2832. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2833. if dialysisFinish.ID == 0 {
  2834. service.CreateDialysisFinish(finish)
  2835. }
  2836. //孝康
  2837. if adminUserInfo.Org.Id == 10693 {
  2838. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2839. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2840. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2841. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2842. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2843. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2844. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2845. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2846. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2847. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2848. }
  2849. if adminUserInfo.Org.Id == 10697 {
  2850. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2851. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2852. lastWeightAfter.LastAfterWeight = floatAfeter
  2853. }
  2854. if adminUserInfo.Org.Id == 10721 {
  2855. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2856. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2857. }
  2858. tempassessmentAfterDislysis.RecordTime = dialysisOrder.EndTime
  2859. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2860. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2861. redis := service.RedisClient()
  2862. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2863. redis.Set(keyOne, "", time.Second)
  2864. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2865. redis.Set(keyTwo, "", time.Second)
  2866. defer redis.Close()
  2867. //清空key 值
  2868. redis.Set(key, "", time.Second)
  2869. if err != nil {
  2870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2871. return
  2872. }
  2873. if dialysisOrder == nil {
  2874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2875. return
  2876. }
  2877. if dialysisOrder.Stage == 2 {
  2878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2879. return
  2880. }
  2881. if dialysisOrder.Stage == 1 {
  2882. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2883. finish := models.XtDialysisFinish{
  2884. IsFinish: 1,
  2885. UserOrgId: adminUserInfo.Org.Id,
  2886. Status: 1,
  2887. Ctime: time.Now().Unix(),
  2888. Mtime: 0,
  2889. Module: 8,
  2890. RecordDate: recordDate.Unix(),
  2891. Sourse: 1,
  2892. PatientId: id,
  2893. }
  2894. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2895. if dialysisFinish.ID == 0 {
  2896. service.CreateDialysisFinish(finish)
  2897. }
  2898. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2899. redis := service.RedisClient()
  2900. defer redis.Close()
  2901. //清空key 值
  2902. redis.Set(key, "", time.Second)
  2903. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2904. redis.Set(keyOne, "", time.Second)
  2905. //结束时候透析次数加1
  2906. service.UpdateSolutionByPatientId(id)
  2907. //下机完自动消毒,针对长沙南雅
  2908. if dialysisOrder.Stage == 1 {
  2909. 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 {
  2910. //根据床位号获取设备型号
  2911. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2912. //查询使用消毒最后一条消毒记录
  2913. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2914. fmt.Println("err", err)
  2915. if err == gorm.ErrRecordNotFound {
  2916. //查找排班
  2917. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2918. //查询改设备是否有消毒计划
  2919. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2920. //根据床位号获取设备id
  2921. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2922. //查询病人信息
  2923. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2924. var con = ""
  2925. if patients.IsInfectious == 0 {
  2926. con = ""
  2927. }
  2928. if patients.IsInfectious == 1 {
  2929. con = "无"
  2930. }
  2931. if patients.IsInfectious == 2 {
  2932. con = "有"
  2933. }
  2934. if errcode == nil {
  2935. var end_time int64
  2936. end_time = endDate.Unix() + plan.DisinfecTime*60
  2937. //新增消毒
  2938. information := models.DeviceInformation{
  2939. Date: dialysisOrder.DialysisDate,
  2940. Zone: dialysisOrder.ZoneId,
  2941. Class: dialysisOrder.SchedualType,
  2942. BedNumber: dialysisOrder.BedID,
  2943. PatientId: dialysisOrder.PatientId,
  2944. DialysisMode: scheduleByPatient.ModeId,
  2945. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2946. Disinfection: 1,
  2947. DialysisConcentration: 1,
  2948. DisinfectionStatus: 1,
  2949. Move: 1,
  2950. UserOrgId: dialysisOrder.UserOrgId,
  2951. DisinfectType: plan.Way,
  2952. DisinfectantType: plan.MachineDisinfectant,
  2953. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2954. Disinfectant: plan.Disinfectant,
  2955. Ctime: time.Now().Unix(),
  2956. Status: 1,
  2957. SignName: nurseID,
  2958. EquimentId: addmacher.ID,
  2959. DisinfectionResidue: 2,
  2960. Bed: addmacher.BedNumber,
  2961. StartTime: dialysisOrder.StartTime,
  2962. EndTime: dialysisOrder.EndTime,
  2963. Contagion: con,
  2964. WeightLoss: 0,
  2965. Hyperfiltratio: 0,
  2966. DialysisHour: "",
  2967. MachineRun: 1,
  2968. DisinfecStartime: endDate.Unix(),
  2969. DisinfecEndtime: end_time,
  2970. }
  2971. err := service.CreateInformationTwo(&information)
  2972. fmt.Println("报错", err)
  2973. }
  2974. }
  2975. }
  2976. }
  2977. dialysisOrder.Stage = 2
  2978. dialysisOrder.FinishNurse = nurseID
  2979. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2980. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2981. dialysisOrder.EndTime = endDate.Unix()
  2982. // 长沙南雅需求
  2983. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2984. //获取最后1条监测的数据
  2985. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2986. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2987. var accumulatedBloodVolume float64
  2988. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2989. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2990. fmt.Println(err)
  2991. // 查询未执行的医嘱
  2992. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2993. for _, item := range doctorAdvice {
  2994. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2995. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2996. redis := service.RedisClient()
  2997. //清空key 值
  2998. redis.Set(key, "", time.Second)
  2999. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  3000. redis.Set(keyTwo, "", time.Second)
  3001. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3002. redis.Set(keyThree, "", time.Second)
  3003. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  3004. theTime := toTime.Format("2006-01-02")
  3005. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3006. redis.Set(keyFour, "", time.Second)
  3007. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3008. redis.Set(keyFive, "", time.Second)
  3009. defer redis.Close()
  3010. }
  3011. }
  3012. go func() {
  3013. ssoDomain := beego.AppConfig.String("call_domain")
  3014. api := ssoDomain + "/index/downpatient"
  3015. values := make(url.Values)
  3016. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  3017. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3018. values.Set("patient_id", strconv.FormatInt(id, 10))
  3019. http.PostForm(api, values)
  3020. }()
  3021. if err == nil {
  3022. c.ServeSuccessJSON(map[string]interface{}{
  3023. "dialysisOrder": dialysisOrder,
  3024. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  3025. })
  3026. } else {
  3027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3028. }
  3029. }
  3030. //查找是否开启配置
  3031. //orderSetting, _ := service.GetDialysisOrderSetting(adminUserInfo.Org.Id)
  3032. ////开启下机扣减
  3033. //if orderSetting.IsOpen == 1 {
  3034. //
  3035. // //查询今日患者排班的模式
  3036. // db := service.XTWriteDB()
  3037. // // 开始外部循环的事务
  3038. // tx := db.Begin()
  3039. // // 在函数结束时处理事务回滚
  3040. // defer func() {
  3041. // if r := recover(); r != nil {
  3042. // tx.Rollback()
  3043. // }
  3044. // }()
  3045. //
  3046. // schedule, _ := service.GetDialysisOrderSchedule(id, recordDate.Unix(), adminUserInfo.Org.Id, tx)
  3047. //
  3048. // if schedule.ModeId == 1 {
  3049. // //扣减库存
  3050. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3051. //
  3052. // patient, _ := service.GetSfPatientById(tx, id)
  3053. // var over_count int64
  3054. // if schedule.ModeId == 1 {
  3055. // over_count = patient.HdCount
  3056. // }
  3057. // if schedule.ModeId == 2 {
  3058. // over_count = patient.HdfCount
  3059. // }
  3060. //
  3061. // if schedule.ModeId == 3 {
  3062. // over_count = patient.HdhpCount
  3063. // }
  3064. // if schedule.ModeId == 4 {
  3065. // over_count = patient.HpCount
  3066. // }
  3067. // if schedule.ModeId == 5 {
  3068. // over_count = patient.OtherCount
  3069. // }
  3070. // patientCountFlow := models.SfPatientCountFlow{
  3071. // PatientId: id,
  3072. // ModeId: schedule.ModeId,
  3073. // Count: 1,
  3074. // Status: 1,
  3075. // Ctime: time.Now().Unix(),
  3076. // Mtime: time.Now().Unix(),
  3077. // RecordDate: recordDate.Unix(),
  3078. // UserOrgId: adminUserInfo.Org.Id,
  3079. // Creater: adminUserInfo.AdminUser.Id,
  3080. // IsType: 1,
  3081. // OverCount: over_count,
  3082. // WarehouseOutId: 0,
  3083. // }
  3084. //
  3085. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3086. // }
  3087. //
  3088. // if schedule.ModeId == 2 {
  3089. //
  3090. // //扣减库存
  3091. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3092. //
  3093. // patient, _ := service.GetSfPatientById(tx, id)
  3094. // var over_count int64
  3095. // if schedule.ModeId == 1 {
  3096. // over_count = patient.HdCount
  3097. // }
  3098. // if schedule.ModeId == 2 {
  3099. // over_count = patient.HdfCount
  3100. // }
  3101. //
  3102. // if schedule.ModeId == 3 {
  3103. // over_count = patient.HdhpCount
  3104. // }
  3105. // if schedule.ModeId == 4 {
  3106. // over_count = patient.HpCount
  3107. // }
  3108. // if schedule.ModeId == 5 {
  3109. // over_count = patient.OtherCount
  3110. // }
  3111. // patientCountFlow := models.SfPatientCountFlow{
  3112. // PatientId: id,
  3113. // ModeId: schedule.ModeId,
  3114. // Count: 1,
  3115. // Status: 1,
  3116. // Ctime: time.Now().Unix(),
  3117. // Mtime: time.Now().Unix(),
  3118. // RecordDate: recordDate.Unix(),
  3119. // UserOrgId: adminUserInfo.Org.Id,
  3120. // Creater: adminUserInfo.AdminUser.Id,
  3121. // IsType: 2,
  3122. // OverCount: over_count,
  3123. // WarehouseOutId: 0,
  3124. // }
  3125. //
  3126. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3127. // }
  3128. //
  3129. // if schedule.ModeId == 3 {
  3130. //
  3131. // //扣减库存
  3132. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3133. //
  3134. // patient, _ := service.GetSfPatientById(tx, id)
  3135. // var over_count int64
  3136. // if schedule.ModeId == 1 {
  3137. // over_count = patient.HdCount
  3138. // }
  3139. // if schedule.ModeId == 2 {
  3140. // over_count = patient.HdfCount
  3141. // }
  3142. //
  3143. // if schedule.ModeId == 3 {
  3144. // over_count = patient.HdhpCount
  3145. // }
  3146. // if schedule.ModeId == 4 {
  3147. // over_count = patient.HpCount
  3148. // }
  3149. // if schedule.ModeId == 5 {
  3150. // over_count = patient.OtherCount
  3151. // }
  3152. // patientCountFlow := models.SfPatientCountFlow{
  3153. // PatientId: id,
  3154. // ModeId: schedule.ModeId,
  3155. // Count: 1,
  3156. // Status: 1,
  3157. // Ctime: time.Now().Unix(),
  3158. // Mtime: time.Now().Unix(),
  3159. // RecordDate: recordDate.Unix(),
  3160. // UserOrgId: adminUserInfo.Org.Id,
  3161. // Creater: adminUserInfo.AdminUser.Id,
  3162. // IsType: 3,
  3163. // OverCount: over_count,
  3164. // WarehouseOutId: 0,
  3165. // }
  3166. //
  3167. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3168. // }
  3169. // if schedule.ModeId == 4 {
  3170. //
  3171. // //扣减库存
  3172. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3173. //
  3174. // patient, _ := service.GetSfPatientById(tx, id)
  3175. // var over_count int64
  3176. // if schedule.ModeId == 1 {
  3177. // over_count = patient.HdCount
  3178. // }
  3179. // if schedule.ModeId == 2 {
  3180. // over_count = patient.HdfCount
  3181. // }
  3182. //
  3183. // if schedule.ModeId == 3 {
  3184. // over_count = patient.HdhpCount
  3185. // }
  3186. // if schedule.ModeId == 4 {
  3187. // over_count = patient.HpCount
  3188. // }
  3189. // if schedule.ModeId == 5 {
  3190. // over_count = patient.OtherCount
  3191. // }
  3192. // patientCountFlow := models.SfPatientCountFlow{
  3193. // PatientId: id,
  3194. // ModeId: schedule.ModeId,
  3195. // Count: 1,
  3196. // Status: 1,
  3197. // Ctime: time.Now().Unix(),
  3198. // Mtime: time.Now().Unix(),
  3199. // RecordDate: recordDate.Unix(),
  3200. // UserOrgId: adminUserInfo.Org.Id,
  3201. // Creater: adminUserInfo.AdminUser.Id,
  3202. // IsType: 4,
  3203. // OverCount: over_count,
  3204. // WarehouseOutId: 0,
  3205. // }
  3206. //
  3207. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3208. // }
  3209. // if schedule.ModeId != 1 && schedule.ModeId != 2 && schedule.ModeId != 3 && schedule.ModeId != 4 {
  3210. //
  3211. // //扣减库存
  3212. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3213. //
  3214. // patient, _ := service.GetSfPatientById(tx, id)
  3215. // var over_count int64
  3216. // if schedule.ModeId == 1 {
  3217. // over_count = patient.HdCount
  3218. // }
  3219. // if schedule.ModeId == 2 {
  3220. // over_count = patient.HdfCount
  3221. // }
  3222. //
  3223. // if schedule.ModeId == 3 {
  3224. // over_count = patient.HdhpCount
  3225. // }
  3226. // if schedule.ModeId == 4 {
  3227. // over_count = patient.HpCount
  3228. // }
  3229. // if schedule.ModeId == 5 {
  3230. // over_count = patient.OtherCount
  3231. // }
  3232. // patientCountFlow := models.SfPatientCountFlow{
  3233. // PatientId: id,
  3234. // ModeId: schedule.ModeId,
  3235. // Count: 1,
  3236. // Status: 1,
  3237. // Ctime: time.Now().Unix(),
  3238. // Mtime: time.Now().Unix(),
  3239. // RecordDate: recordDate.Unix(),
  3240. // UserOrgId: adminUserInfo.Org.Id,
  3241. // Creater: adminUserInfo.AdminUser.Id,
  3242. // IsType: 5,
  3243. // OverCount: over_count,
  3244. // WarehouseOutId: 0,
  3245. // }
  3246. //
  3247. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3248. // }
  3249. //
  3250. // tx.Commit()
  3251. // return
  3252. //}
  3253. }
  3254. func (c *DialysisAPIController) GetAllZone() {
  3255. adminUserInfo := c.GetMobileAdminUserInfo()
  3256. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  3257. if err == nil {
  3258. c.ServeSuccessJSON(map[string]interface{}{
  3259. "zone": zone,
  3260. })
  3261. }
  3262. }
  3263. func (c *DialysisAPIController) GetSchedualPatientsList() {
  3264. adminUserInfo := c.GetMobileAdminUserInfo()
  3265. page, _ := c.GetInt64("page", 1)
  3266. limit, _ := c.GetInt64("limit", 10)
  3267. schedulType, _ := c.GetInt64("schedul_type", 0)
  3268. startTime, _ := c.GetInt64("schedul_time", 0)
  3269. partitionType, _ := c.GetInt64("partition_type", 0)
  3270. keywords := c.GetString("keywords")
  3271. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3272. if err == nil {
  3273. c.ServeSuccessJSON(map[string]interface{}{
  3274. "schedule": dialysisSchedule,
  3275. })
  3276. }
  3277. return
  3278. }
  3279. // /m/api/dialysis/start [post]
  3280. // @param patient_id:int
  3281. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3282. // @param nurse:int 上机护士
  3283. // @param bed:int 床位号
  3284. func (this *DialysisAPIController) StartDialysis() {
  3285. patientID, _ := this.GetInt64("patient_id")
  3286. recordDateStr := this.GetString("record_date")
  3287. nurseID, _ := this.GetInt64("start_nurse")
  3288. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3289. blood_drawing, _ := this.GetInt64("blood_drawing")
  3290. schedual_type, _ := this.GetInt64("schedual_type")
  3291. bedID, _ := this.GetInt64("bed")
  3292. start_time := this.GetString("start_time")
  3293. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3294. change_nurse, _ := this.GetInt64("change_nurse")
  3295. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3296. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3297. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3298. puncture_needle := this.GetString("puncture_needle")
  3299. puncture_way := this.GetString("puncture_way")
  3300. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3301. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3302. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3303. zone_id, _ := this.GetInt64("zone_id")
  3304. elecsign := this.GetString("url")
  3305. nuclein_date_str := this.GetString("nuclein_date_str")
  3306. schedule_remark := this.GetString("schedule_remark")
  3307. order_remark := this.GetString("order_remark")
  3308. catheter_operation := this.GetString("catheter_operation")
  3309. blood_flow_volume := this.GetString("blood_flow_volume")
  3310. dialysis_strainer := this.GetString("dialysis_strainer")
  3311. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3312. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3313. return
  3314. }
  3315. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3316. if parseStartDateErr != nil {
  3317. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3318. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3319. return
  3320. }
  3321. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3322. if parseErr != nil {
  3323. this.ErrorLog("时间解析失败:%v", parseErr)
  3324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3325. return
  3326. }
  3327. adminUserInfo := this.GetMobileAdminUserInfo()
  3328. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3329. if getPatientErr != nil {
  3330. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3332. return
  3333. } else if patient == nil {
  3334. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3335. return
  3336. }
  3337. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3338. if getNurseErr != nil {
  3339. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3340. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3341. return
  3342. } else if nurse == nil {
  3343. this.ErrorLog("护士不存在")
  3344. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3345. return
  3346. }
  3347. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3348. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3349. if getDeviceNumberErr != nil {
  3350. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3352. return
  3353. } else if deviceNumber == nil {
  3354. this.ErrorLog("床位号不存在")
  3355. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3356. return
  3357. }
  3358. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3359. if getRecordErr != nil {
  3360. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3361. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3362. return
  3363. } else if dialysisRecord != nil {
  3364. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3365. return
  3366. }
  3367. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3368. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3369. timeLayout := "2006-01-02 15:04:05"
  3370. loc, _ := time.LoadLocation("Local")
  3371. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3372. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3373. schedulestartTime := theStartTime.Unix()
  3374. scheduleendTime := theEndTime.Unix()
  3375. var theNucleinDate int64
  3376. timeLayoutOne := "2006-01-02"
  3377. if len(nuclein_date_str) > 0 {
  3378. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3379. if err != nil {
  3380. utils.ErrorLog(err.Error())
  3381. }
  3382. theNucleinDate = theTime.Unix()
  3383. }
  3384. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3385. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3386. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3387. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3388. if adminUserInfo.Org.Id == 10679 || adminUserInfo.Org.Id == 10164 {
  3389. record, _ := service.GetDialysisPrescriptionByRecord(adminUserInfo.Org.Id, patientID, schedulestartTime)
  3390. if record.ID == 0 {
  3391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescription)
  3392. return
  3393. }
  3394. }
  3395. //查询该床位是否有人用了
  3396. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3397. if err == gorm.ErrRecordNotFound { //空床位
  3398. // 修改了床位逻辑
  3399. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3400. if daySchedule.ID > 0 {
  3401. daySchedule.PartitionId = deviceNumber.ZoneID
  3402. daySchedule.BedId = bedID
  3403. daySchedule.ScheduleType = schedual_type
  3404. daySchedule.UpdatedTime = time.Now().Unix()
  3405. xtSchedule := models.Schedule{
  3406. PartitionId: deviceNumber.ZoneID,
  3407. BedId: bedID,
  3408. ScheduleType: schedual_type,
  3409. UpdatedTime: time.Now().Unix(),
  3410. }
  3411. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3412. if err != nil {
  3413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3414. return
  3415. }
  3416. }
  3417. } else if err == nil {
  3418. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3419. if order.ID > 0 { //该机位被其他人占用了
  3420. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3421. return
  3422. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3423. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3424. if daySchedule.ID > 0 {
  3425. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3426. if err != nil {
  3427. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3428. return
  3429. }
  3430. }
  3431. }
  3432. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3433. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3434. return
  3435. }
  3436. //else if order.ID == 0 { //该床位没被占用
  3437. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3438. // if daySchedule.ID > 0 {
  3439. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3440. // //daySchedule.BedId = bedID
  3441. // //daySchedule.ScheduleType = schedual_type
  3442. // //daySchedule.UpdatedTime = time.Now().Unix()
  3443. // //err := service.UpdateSchedule(&daySchedule)
  3444. // xtSchedule := models.Schedule{
  3445. // PartitionId: deviceNumber.ZoneID,
  3446. // BedId: bedID,
  3447. // ScheduleType: schedual_type,
  3448. // UpdatedTime: time.Now().Unix(),
  3449. // }
  3450. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3451. // if err != nil {
  3452. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3453. // return
  3454. // }
  3455. // }
  3456. //}
  3457. //}
  3458. } else if err != nil {
  3459. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3460. return
  3461. }
  3462. // 查询信息规挡的设置天数
  3463. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3464. if infor.ID > 0 && infor.WeekDay > 0 {
  3465. var cha_time int64
  3466. timeNowStr := time.Now().Format("2006-01-02")
  3467. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3468. //今日的日期减去设置的日期
  3469. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3470. if cha_time >= recordDate.Unix() {
  3471. //查询审核是否允许
  3472. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3473. //申请状态不允许的情况 拒绝修改
  3474. if infor.ApplicationStatus != 1 {
  3475. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3476. return
  3477. }
  3478. }
  3479. }
  3480. dialysisRecord = &models.DialysisOrder{
  3481. DialysisDate: recordDate.Unix(),
  3482. UserOrgId: adminUserInfo.Org.Id,
  3483. PatientId: patientID,
  3484. Stage: 1,
  3485. BedID: bedID,
  3486. StartNurse: nurseID,
  3487. Status: 1,
  3488. StartTime: startDate.Unix(),
  3489. CreatedTime: time.Now().Unix(),
  3490. UpdatedTime: time.Now().Unix(),
  3491. PunctureNurse: puncture_nurse,
  3492. Creator: adminUserInfo.AdminUser.Id,
  3493. Modifier: adminUserInfo.AdminUser.Id,
  3494. SchedualType: schedual_type,
  3495. WashpipeNurse: washpipe_nurse,
  3496. ChangeNurse: change_nurse,
  3497. DifficultPunctureNurse: difficult_puncture_nurse,
  3498. NewFistulaNurse: new_fistula_nurse,
  3499. ZoneId: zone_id,
  3500. QualityNurseId: quality_nurse_id,
  3501. PunctureNeedle: puncture_needle,
  3502. PunctureWay: puncture_way,
  3503. DialysisIrrigation: dialysis_irrigation,
  3504. DialysisDialyszers: dialysis_dialyszers,
  3505. BloodAccessId: blood_access_id,
  3506. Url: elecsign,
  3507. NucleinDate: theNucleinDate,
  3508. ScheduleRemark: schedule_remark,
  3509. OrderRemark: order_remark,
  3510. CatheterOperation: catheter_operation,
  3511. BloodFlowVolume: blood_flow_volume,
  3512. BloodDrawing: blood_drawing,
  3513. DialysisStrainer: dialysis_strainer,
  3514. }
  3515. //查询该床位是否有人用了
  3516. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3517. if errorscode == gorm.ErrRecordNotFound {
  3518. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3519. finish := models.XtDialysisFinish{
  3520. IsFinish: 1,
  3521. UserOrgId: adminUserInfo.Org.Id,
  3522. Status: 1,
  3523. Ctime: time.Now().Unix(),
  3524. Mtime: 0,
  3525. Module: 6,
  3526. RecordDate: schedulestartTime,
  3527. Sourse: 1,
  3528. PatientId: patientID,
  3529. }
  3530. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3531. if dialysisFinish.ID == 0 {
  3532. service.CreateDialysisFinish(finish)
  3533. }
  3534. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3535. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3536. //统计该患者总次数
  3537. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3538. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3539. }
  3540. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3541. //统计该患者总次数
  3542. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3543. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3544. }
  3545. redis := service.RedisClient()
  3546. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3547. redis.Set(key, "", time.Second)
  3548. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3549. //清空key 值
  3550. redis.Set(keyOne, "", time.Second)
  3551. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3552. //清空key 值
  3553. redis.Set(keyTwo, "", time.Second)
  3554. if createErr != nil {
  3555. this.ErrorLog("上机失败:%v", createErr)
  3556. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3557. return
  3558. }
  3559. }
  3560. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3561. var tempdispose string
  3562. // 只针对中能建
  3563. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3564. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3565. }
  3566. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3567. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3568. }
  3569. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3570. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3571. //}
  3572. var ultrafiltration_rate float64
  3573. var ultrafiltration_rate_one string
  3574. var replacement_rate float64
  3575. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3576. //后期预增脱水量
  3577. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3578. if prescription.ID > 0 {
  3579. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3580. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3581. 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
  3582. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3583. }
  3584. if adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10740 || adminUserInfo.Org.Id == 10745 || adminUserInfo.Org.Id == 9478 {
  3585. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3586. }
  3587. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3588. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3589. }
  3590. //针对医师汇
  3591. if adminUserInfo.Org.Id == 10121 {
  3592. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3593. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3594. }
  3595. //针对通道
  3596. if adminUserInfo.Org.Id == 10234 {
  3597. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3598. }
  3599. //针对监利大垸医院
  3600. if template.TemplateId == 41 {
  3601. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3602. }
  3603. //针对肇庆三鹤血液透析中心
  3604. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3605. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3606. }
  3607. if adminUserInfo.Org.Id == 10469 {
  3608. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3609. }
  3610. if adminUserInfo.Org.Id == 10667 {
  3611. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3612. }
  3613. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3614. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3615. }
  3616. // 只针对方济医院
  3617. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3618. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3619. ultrafiltration_rate = value
  3620. }
  3621. //针对
  3622. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3623. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3624. ultrafiltration_rate = ultrafiltration_rate / 1000
  3625. }
  3626. if adminUserInfo.Org.Id == 10551 {
  3627. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3628. ultrafiltration_rate = ultrafiltration_rate / 1000
  3629. }
  3630. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3631. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3632. ultrafiltration_rate = ultrafiltration_rate / 1000
  3633. }
  3634. if adminUserInfo.Org.Id == 10580 {
  3635. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3636. ultrafiltration_rate = ultrafiltration_rate / 1000
  3637. }
  3638. if adminUserInfo.Org.Id == 10629 {
  3639. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3640. ultrafiltration_rate = ultrafiltration_rate / 1000
  3641. }
  3642. if adminUserInfo.Org.Id == 10644 || adminUserInfo.Org.Id == 10751 {
  3643. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3644. ultrafiltration_rate = ultrafiltration_rate / 1000
  3645. }
  3646. if adminUserInfo.Org.Id == 10751 {
  3647. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3648. ultrafiltration_rate = ultrafiltration_rate / 1000
  3649. }
  3650. if adminUserInfo.Org.Id == 10667 {
  3651. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3652. ultrafiltration_rate = ultrafiltration_rate / 1000
  3653. }
  3654. if adminUserInfo.Org.Id == 10693 {
  3655. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3656. ultrafiltration_rate = ultrafiltration_rate
  3657. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3658. }
  3659. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3660. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3661. ultrafiltration_rate = ultrafiltration_rate
  3662. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3663. }
  3664. if adminUserInfo.Org.Id == 10206 {
  3665. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3666. ultrafiltration_rate = ultrafiltration_rate
  3667. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3668. }
  3669. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3670. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3671. ultrafiltration_rate = ultrafiltration_rate
  3672. }
  3673. if adminUserInfo.Org.Id == 10702 {
  3674. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3675. ultrafiltration_rate = ultrafiltration_rate / 1000
  3676. }
  3677. if adminUserInfo.Org.Id == 10752 {
  3678. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3679. ultrafiltration_rate = ultrafiltration_rate / 1000
  3680. }
  3681. if adminUserInfo.Org.Id == 10723 {
  3682. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3683. ultrafiltration_rate = ultrafiltration_rate / 1000
  3684. }
  3685. if adminUserInfo.Org.Id == 10721 {
  3686. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3687. ultrafiltration_rate = ultrafiltration_rate / 1000
  3688. }
  3689. if adminUserInfo.Org.Id == 10766 {
  3690. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3691. ultrafiltration_rate = ultrafiltration_rate / 1000
  3692. }
  3693. if adminUserInfo.Org.Id == 10757 {
  3694. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3695. ultrafiltration_rate = ultrafiltration_rate / 1000
  3696. }
  3697. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10757 {
  3698. if prescription.ModeId == 2 {
  3699. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3700. if totalMin == 0 {
  3701. totalMin = 240
  3702. }
  3703. if prescription.ReplacementTotal == 0 {
  3704. prescription.ReplacementTotal = 15
  3705. }
  3706. //乘10 除10是为了保留一位小数
  3707. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3708. }
  3709. }
  3710. if adminUserInfo.Org.Id == 10766 {
  3711. if prescription.ModeId == 2 || prescription.ModeId == 13 {
  3712. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3713. if totalMin == 0 {
  3714. totalMin = 240
  3715. }
  3716. if prescription.DisplaceLiquiValue == 0 {
  3717. prescription.DisplaceLiquiValue = 15
  3718. }
  3719. //乘10 除10是为了保留一位小数
  3720. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3721. }
  3722. }
  3723. if adminUserInfo.Org.Id == 10752 {
  3724. if prescription.ModeId == 2 {
  3725. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3726. if totalMin == 0 {
  3727. totalMin = 240
  3728. }
  3729. if prescription.ReplacementTotal == 0 {
  3730. prescription.ReplacementTotal = 15
  3731. }
  3732. //乘10 除10是为了保留一位小数
  3733. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3734. }
  3735. }
  3736. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10744 {
  3737. if prescription.ModeId == 2 {
  3738. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3739. if totalMin == 0 {
  3740. totalMin = 240
  3741. }
  3742. if prescription.DisplaceLiquiValue == 0 {
  3743. prescription.ReplacementTotal = 32
  3744. }
  3745. //乘10 除10是为了保留一位小数
  3746. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3747. }
  3748. }
  3749. }
  3750. }
  3751. if adminUserInfo.Org.Id == 10172 {
  3752. if prescription.ID == 0 {
  3753. if prescription.ModeId == 2 {
  3754. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3755. if totalMin == 0 {
  3756. totalMin = 240
  3757. }
  3758. if prescription.ReplacementTotal == 0 {
  3759. prescription.ReplacementTotal = 15
  3760. }
  3761. //乘10 除10是为了保留一位小数
  3762. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3763. }
  3764. }
  3765. }
  3766. record := models.MonitoringRecord{
  3767. UserOrgId: adminUserInfo.Org.Id,
  3768. PatientId: patientID,
  3769. DialysisOrderId: dialysisRecord.ID,
  3770. MonitoringDate: schedulestartTime,
  3771. OperateTime: startDate.Unix(),
  3772. // MonitoringTime: recordTime,
  3773. MonitoringNurse: nurseID,
  3774. Dispose: tempdispose,
  3775. UltrafiltrationRate: ultrafiltration_rate,
  3776. UltrafiltrationVolume: 0,
  3777. Status: 1,
  3778. CreatedTime: time.Now().Unix(),
  3779. UpdatedTime: time.Now().Unix(),
  3780. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3781. ReplacementRate: replacement_rate,
  3782. }
  3783. //只针对广慈医院
  3784. 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 {
  3785. // 查询病人是否有透前评估数据
  3786. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3787. //如果有数据就插入
  3788. if errcode == nil {
  3789. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3790. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3791. record.BreathingRate = befor.BreathingRate
  3792. record.PulseFrequency = befor.PulseFrequency
  3793. record.Temperature = befor.Temperature
  3794. }
  3795. }
  3796. //孝昌
  3797. if adminUserInfo.Org.Id == 10693 {
  3798. // 查询病人是否有透前评估数据
  3799. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3800. //如果有数据就插入
  3801. if errcode == nil {
  3802. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3803. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3804. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3805. record.BreathingRate = befor.BreathingRate
  3806. }
  3807. }
  3808. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3809. if newdialysisRecord.ID > 0 {
  3810. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3811. record.Temperature = 36.5
  3812. record.ArterialPressure = -100
  3813. record.DialysateTemperature = 36.5
  3814. record.Conductivity = 14
  3815. record.BreathingRate = "20"
  3816. record.VenousPressure = 80
  3817. record.TransmembranePressure = 60
  3818. record.Dispose = catheter_operation
  3819. }
  3820. //针对新化博翔
  3821. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3822. record.BloodOxygenSaturation = "99"
  3823. record.Conductivity = 14
  3824. record.DialysateTemperature = 36.5
  3825. record.BreathingRate = "20"
  3826. }
  3827. //针对兰溪人民医院的需求
  3828. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3829. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3830. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3831. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3832. record.Temperature = befor.Temperature
  3833. record.PulseFrequency = befor.PulseFrequency
  3834. record.BreathingRate = befor.BreathingRate
  3835. }
  3836. //针对乐山友谊医院的需求
  3837. if adminUserInfo.Org.Id == 10677 {
  3838. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3839. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3840. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3841. record.Temperature = befor.Temperature
  3842. record.PulseFrequency = befor.PulseFrequency
  3843. record.BreathingRate = befor.BreathingRate
  3844. }
  3845. //新化博翔
  3846. if adminUserInfo.Org.Id == 10447 {
  3847. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3848. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3849. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3850. record.BreathingRate = befor.BreathingRate
  3851. }
  3852. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3853. record.PulseFrequency = 80
  3854. record.Temperature = 36.5
  3855. }
  3856. //诊断灵山圣康
  3857. if adminUserInfo.Org.Id == 10375 {
  3858. record.Conductivity = 13.8
  3859. record.DialysateTemperature = 37
  3860. record.DialysateFlow = 500
  3861. record.BloodFlowVolume = 200
  3862. record.BreathingRate = "18"
  3863. record.SodiumConcentration = 140
  3864. }
  3865. //江成肾病医院
  3866. if adminUserInfo.Org.Id == 10517 {
  3867. record.SodiumConcentration = 138
  3868. record.DialysateTemperature = 36.5
  3869. }
  3870. //濉溪杏康血液透析中心
  3871. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3872. record.BloodFlowVolume = prescription.BloodFlowVolume
  3873. }
  3874. //胶州少海医院
  3875. if adminUserInfo.Org.Id == 10735 || adminUserInfo.Org.Id == 9478 {
  3876. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3877. dialysisPrescription, _ := service.GetDialysisPrescription(patientID, adminUserInfo.Org.Id, recordDate.Unix())
  3878. record.BreathingRate = befor.BreathingRate
  3879. record.BloodFlowVolume = dialysisPrescription.BloodFlowVolume
  3880. record.Temperature = befor.Temperature
  3881. record.PulseFrequency = befor.PulseFrequency
  3882. }
  3883. if adminUserInfo.Org.Id != 10683 {
  3884. err = service.CreateMonitor(&record)
  3885. }
  3886. //记录日志
  3887. byterequest, _ := json.Marshal(record)
  3888. monitorRecordLog := models.XtMonitorRecordLog{
  3889. RecordDate: record.MonitoringDate,
  3890. PatientId: record.PatientId,
  3891. Module: 1,
  3892. AdminUserId: adminUserInfo.AdminUser.Id,
  3893. Ctime: time.Now().Unix(),
  3894. Mtime: 0,
  3895. Status: 1,
  3896. UserOrgId: record.UserOrgId,
  3897. ErrLog: string(byterequest),
  3898. Source: "执行上机时新增监测",
  3899. }
  3900. service.CreateMonitorRecordLog(monitorRecordLog)
  3901. finish := models.XtDialysisFinish{
  3902. IsFinish: 1,
  3903. UserOrgId: adminUserInfo.Org.Id,
  3904. Status: 1,
  3905. Ctime: time.Now().Unix(),
  3906. Mtime: 0,
  3907. Module: 7,
  3908. RecordDate: schedulestartTime,
  3909. Sourse: 1,
  3910. PatientId: patientID,
  3911. }
  3912. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3913. if dialysisFinish.ID == 0 {
  3914. service.CreateDialysisFinish(finish)
  3915. }
  3916. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3917. redis := service.RedisClient()
  3918. //清空key 值
  3919. redis.Set(key, "", time.Second)
  3920. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3921. redis.Set(keyOne, "", time.Second)
  3922. defer redis.Close()
  3923. if err != nil {
  3924. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3925. return
  3926. }
  3927. }
  3928. go func() {
  3929. ssoDomain := beego.AppConfig.String("call_domain")
  3930. api := ssoDomain + "/index/uppatient"
  3931. values := make(url.Values)
  3932. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3933. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3934. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3935. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3936. http.PostForm(api, values)
  3937. }()
  3938. this.ServeSuccessJSON(map[string]interface{}{
  3939. "dialysis_order": newdialysisRecord,
  3940. "monitor": record,
  3941. })
  3942. return
  3943. }
  3944. func (c *DialysisAPIController) PostSolution() {
  3945. id, _ := c.GetInt64("patient", 0)
  3946. recordDateStr := c.GetString("record_date")
  3947. if id <= 0 {
  3948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3949. return
  3950. }
  3951. adminUserInfo := c.GetMobileAdminUserInfo()
  3952. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3953. if patient.ID == 0 {
  3954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3955. return
  3956. }
  3957. if len(recordDateStr) == 0 {
  3958. recordDateStr = time.Now().Format("2006-01-02")
  3959. }
  3960. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3961. if parseDateErr != nil {
  3962. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3964. return
  3965. }
  3966. mode_id, _ := c.GetInt64("mode_id", 0)
  3967. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3968. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3969. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3970. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3971. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3972. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3973. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3974. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3975. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3976. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3977. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3978. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3979. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3980. kalium, _ := c.GetFloat("kalium", 0)
  3981. sodium, _ := c.GetFloat("sodium", 0)
  3982. calcium, _ := c.GetFloat("calcium", 0)
  3983. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3984. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3985. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3986. glucose, _ := c.GetFloat("glucose", 0)
  3987. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3988. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3989. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3990. conductivity, _ := c.GetFloat("conductivity", 0)
  3991. remark := c.GetString("remark")
  3992. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3993. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3994. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3995. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3996. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3997. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3998. special_medicine_other := c.GetString("special_medicine_other")
  3999. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  4000. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  4001. blood_access, _ := c.GetInt64("blood_access", 0)
  4002. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  4003. body_fluid_other := c.GetString("body_fluid_other")
  4004. replacement_total, _ := c.GetFloat("replacement_total", 0)
  4005. niprocart, _ := c.GetInt64("niprocart", 0)
  4006. jms, _ := c.GetInt64("jms", 0)
  4007. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  4008. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  4009. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  4010. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  4011. filtryzer, _ := c.GetInt64("filtryzer", 0)
  4012. target_ktv, _ := c.GetFloat("target_ktv", 0)
  4013. dialyzers, _ := c.GetInt64("dialyzers", 0)
  4014. injector, _ := c.GetInt64("injector", 0)
  4015. bloodlines, _ := c.GetInt64("bloodlines", 0)
  4016. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  4017. safe_package, _ := c.GetInt64("package", 0)
  4018. a_liquid, _ := c.GetInt64("a_liquid", 0)
  4019. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  4020. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  4021. blood := c.GetString("blood")
  4022. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  4023. dialysis_irrigation := c.GetString("dialysis_irrigation")
  4024. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  4025. displace_speed := c.GetString("displace_speed")
  4026. illness, _ := c.GetInt64("illness")
  4027. amylaceum := c.GetString("amylaceum")
  4028. single_time := c.GetString("single_time")
  4029. single_water := c.GetString("single_water")
  4030. replacement_flow := c.GetString("replacement_flow")
  4031. plasma_separator := c.GetString("plasma_separator")
  4032. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  4033. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  4034. oxygen_flow := c.GetString("oxygen_flow")
  4035. oxygen_time := c.GetString("oxygen_time")
  4036. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  4037. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  4038. puncture_needle := c.GetString("puncture_needle")
  4039. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  4040. epo := c.GetString("epo")
  4041. epo_count, _ := c.GetFloat("epo_count", 0)
  4042. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  4043. pre_impulse := c.GetString("pre_impulse")
  4044. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  4045. admin_user_id, _ := c.GetInt64("admin_user_id")
  4046. is_water := c.GetString("is_water")
  4047. add_amount, _ := c.GetFloat("add_amount")
  4048. reduce_amount, _ := c.GetFloat("reduce_amount")
  4049. prescribing_number, _ := c.GetFloat("prescribing_number")
  4050. treatment_remark := c.GetString("treatment_remark")
  4051. prescription_sodium := c.GetString("prescription_sodium")
  4052. start_sodium := c.GetString("start_sodium")
  4053. sodium_curve := c.GetString("sodium_curve")
  4054. var is_war int64
  4055. if is_water == "是" {
  4056. is_war = 1
  4057. }
  4058. if is_water == "否" {
  4059. is_war = 2
  4060. }
  4061. if is_water == "请选择" {
  4062. is_war = 0
  4063. }
  4064. drhy_water := c.GetString("drhy_water")
  4065. dry_water_hour := c.GetString("dry_water_hour")
  4066. water_machine := c.GetString("water_machine")
  4067. dialysis_remark := c.GetString("dialysis_remark")
  4068. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  4069. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  4070. prescription_water, _ := c.GetFloat("prescription_water")
  4071. dialysis_strainer := c.GetString("dialysis_strainer")
  4072. chaptalization := c.GetString("chaptalization")
  4073. washing_time := c.GetString("washing_time")
  4074. warsh_count := c.GetString("warsh_count")
  4075. blood_access_part_id := c.GetString("blood_access_part_id")
  4076. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  4077. dialyzate := c.GetString("dialyzate")
  4078. first_super := c.GetString("first_super")
  4079. is_sequential := c.GetString("is_sequential")
  4080. var fisrt_sup int64
  4081. if first_super == "是" {
  4082. fisrt_sup = 1
  4083. }
  4084. if first_super == "否" {
  4085. fisrt_sup = 2
  4086. }
  4087. if first_super == "请选择" {
  4088. fisrt_sup = 0
  4089. }
  4090. var is_sequen int64
  4091. if is_sequential == "是" {
  4092. is_sequen = 1
  4093. }
  4094. if is_sequential == "否" {
  4095. is_sequen = 2
  4096. }
  4097. if is_sequential == "请选择" {
  4098. is_sequen = 0
  4099. }
  4100. conduct := c.GetString("conduct")
  4101. if mode_id > 0 {
  4102. var str string
  4103. //查找该机构用的是什么透析器
  4104. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  4105. if filedConfig.ID > 0 {
  4106. str = dialyzerPerfusionApparatus
  4107. } else {
  4108. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  4109. }
  4110. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  4111. }
  4112. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4113. //
  4114. //if template.TemplateId == 2 || template.TemplateId == 6 {
  4115. // if appRole.UserType == 3 {
  4116. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4117. // if getPermissionErr != nil {
  4118. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4119. // return
  4120. // } else if headNursePermission == nil {
  4121. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4122. // return
  4123. // }
  4124. // }
  4125. //}
  4126. // 查询信息规挡的设置天数
  4127. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4128. if infor.ID > 0 && infor.WeekDay > 0 {
  4129. var cha_time int64
  4130. timeNowStr := time.Now().Format("2006-01-02")
  4131. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4132. //今日的日期减去设置的日期
  4133. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4134. if cha_time >= recordDate.Unix() {
  4135. //查询审核是否允许
  4136. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  4137. //申请状态不允许的情况 拒绝修改
  4138. if infor.ApplicationStatus != 1 {
  4139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4140. return
  4141. }
  4142. }
  4143. }
  4144. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  4145. var dialysis_dialyszers_id int64
  4146. var dialysis_strainer_id int64
  4147. var dialysis_irrigation_id int64
  4148. if len(goodList) > 0 {
  4149. for _, item := range goodList {
  4150. if item.SpecificationName == dialysis_dialyszers {
  4151. dialysis_dialyszers_id = item.ID
  4152. }
  4153. if item.SpecificationName == dialysis_irrigation {
  4154. dialysis_irrigation_id = item.ID
  4155. }
  4156. if item.SpecificationName == dialysis_strainer {
  4157. dialysis_strainer_id = item.ID
  4158. }
  4159. }
  4160. }
  4161. prescription := models.DialysisPrescription{
  4162. UserOrgId: adminUserInfo.Org.Id,
  4163. PatientId: id,
  4164. RecordDate: recordDate.Unix(),
  4165. ModeId: mode_id,
  4166. DialysisDuration: dialysis_duration,
  4167. Dialyzer: dialyzer,
  4168. PerfusionApparatus: perfusion_apparatus,
  4169. BloodFlowVolume: blood_flow_volume,
  4170. DewaterAmount: dewater_amount,
  4171. DisplaceLiqui: displace_liqui,
  4172. ReplacementWay: replacement_way,
  4173. Anticoagulant: anticoagulant,
  4174. AnticoagulantShouji: anticoagulant_shouji,
  4175. AnticoagulantWeichi: anticoagulant_weichi,
  4176. AnticoagulantZongliang: anticoagulant_zongliang,
  4177. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4178. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4179. Kalium: kalium,
  4180. Sodium: sodium,
  4181. Calcium: calcium,
  4182. Bicarbonate: bicarbonate,
  4183. Glucose: glucose,
  4184. // DryWeight: dry_weight,
  4185. DialysateFlow: dialysate_flow,
  4186. DialysateTemperature: dialysate_temperature,
  4187. Conductivity: conductivity,
  4188. Remark: remark,
  4189. Status: 1,
  4190. CreatedTime: time.Now().Unix(),
  4191. UpdatedTime: time.Now().Unix(),
  4192. DialysisDurationMinute: dialysisDurationMinute,
  4193. DialysisDurationHour: dialysisDurationHour,
  4194. TargetUltrafiltration: targetUltrafiltration,
  4195. DialysateFormulation: dialysateFormulation,
  4196. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4197. BodyFluid: body_fluid,
  4198. SpecialMedicine: special_medicine,
  4199. SpecialMedicineOther: special_medicine_other,
  4200. DisplaceLiquiPart: displace_liqui_part,
  4201. DisplaceLiquiValue: displace_liqui_value,
  4202. BloodAccess: blood_access,
  4203. Ultrafiltration: ultrafiltration,
  4204. BodyFluidOther: body_fluid_other,
  4205. ReplacementTotal: replacement_total,
  4206. Niprocart: niprocart,
  4207. Jms: jms,
  4208. FistulaNeedleSet: fistula_needle_set,
  4209. FistulaNeedleSet16: fistula_needle_set_16,
  4210. Hemoperfusion: hemoperfusion,
  4211. DialyserSterilised: dialyser_sterilised,
  4212. Filtryzer: filtryzer,
  4213. TargetKtv: target_ktv,
  4214. Dialyzers: dialyzers,
  4215. Injector: injector,
  4216. Bloodlines: bloodlines,
  4217. TubingHemodialysis: tubing_hemodialysis,
  4218. Package: safe_package,
  4219. ALiquid: a_liquid,
  4220. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  4221. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  4222. Blood: blood,
  4223. DialysisDialyszers: dialysis_dialyszers,
  4224. DialysisIrrigation: dialysis_irrigation,
  4225. AntioxidantCommodityName: antioxidant_commodity_name,
  4226. DisplaceSpeed: displace_speed,
  4227. Illness: illness,
  4228. Amylaceum: amylaceum,
  4229. SingleWater: single_water,
  4230. SingleTime: single_time,
  4231. ReplacementFlow: replacement_flow,
  4232. PlasmaSeparator: plasma_separator,
  4233. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  4234. OxygenUptake: oxygen_uptake,
  4235. OxygenTime: oxygen_time,
  4236. OxygenFlow: oxygen_flow,
  4237. HemodialysisPipelines: hemodialysis_pipelines,
  4238. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4239. PunctureNeedle: puncture_needle,
  4240. PunctureNeedleCount: puncture_needle_count,
  4241. Epo: epo,
  4242. EpoCount: epo_count,
  4243. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4244. PreImpulse: impulse,
  4245. AdminUserId: admin_user_id,
  4246. IsWater: is_war,
  4247. DrhyWater: drhy_water,
  4248. DryWaterHour: dry_water_hour,
  4249. WaterMachine: water_machine,
  4250. AddAmount: add_amount,
  4251. ReduceAmount: reduce_amount,
  4252. DialysisRemark: dialysis_remark,
  4253. PrescribingNumber: prescribing_number,
  4254. PrescriptionSodium: prescription_sodium,
  4255. StartSodium: start_sodium,
  4256. SodiumCurve: sodium_curve,
  4257. TreatmentRemark: treatment_remark,
  4258. DialysisFluidFlow: dialysis_fluid_flow,
  4259. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4260. PrescriptionWater: prescription_water,
  4261. DialysisStrainer: dialysis_strainer,
  4262. Chaptalization: chaptalization,
  4263. WashingTime: washing_time,
  4264. WarshCount: warsh_count,
  4265. BloodAccessPartId: blood_access_part_id,
  4266. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4267. Dialyzate: dialyzate,
  4268. DialysisDialyszersId: dialysis_dialyszers_id,
  4269. DialysisIrrigationId: dialysis_irrigation_id,
  4270. DialysisStrainerId: dialysis_strainer_id,
  4271. FirstSuper: fisrt_sup,
  4272. IsSequential: is_sequen,
  4273. Conduct: conduct,
  4274. }
  4275. if adminUserInfo.Org.Id == 10721 {
  4276. if prescription.ModeId == 2 {
  4277. if prescription.ReplacementTotal == 0 {
  4278. prescription.ReplacementTotal = 15
  4279. }
  4280. }
  4281. }
  4282. if adminUserInfo.Org.Id == 10766 || adminUserInfo.Org.Id == 9478 {
  4283. if prescription.ModeId == 2 || prescription.ModeId == 13 {
  4284. if prescription.ReplacementTotal == 0 {
  4285. prescription.ReplacementTotal = 15
  4286. }
  4287. }
  4288. }
  4289. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4290. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  4291. //
  4292. if appRole.UserType == 2 || appRole.UserType == 1 {
  4293. prescription_doctor = adminUserInfo.AdminUser.Id
  4294. prescription.PrescriptionDoctor = prescription_doctor
  4295. }
  4296. if dialysisPrescription.ID == 0 { //新增
  4297. prescription.Creater = adminUserInfo.AdminUser.Id
  4298. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4299. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4300. }
  4301. } else { //修改
  4302. if dialysisPrescription.Creater == 0 {
  4303. prescription.Creater = adminUserInfo.AdminUser.Id
  4304. } else {
  4305. prescription.Creater = dialysisPrescription.Creater
  4306. if adminUserInfo.Org.Id == 9882 {
  4307. if appRole.UserType == 2 || appRole.UserType == 1 {
  4308. prescription.Creater = adminUserInfo.AdminUser.Id
  4309. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  4310. }
  4311. }
  4312. }
  4313. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4314. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4315. }
  4316. //if/**/
  4317. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4318. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  4319. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4320. // if getPermissionErr != nil {
  4321. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4322. // return
  4323. // } else if headNursePermission == nil {
  4324. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4325. // return
  4326. // }
  4327. //}
  4328. //prescription.Creater = dialysisPrescription.Creater
  4329. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4330. prescription.Modifier = adminUserInfo.AdminUser.Id
  4331. prescription.ID = dialysisPrescription.ID
  4332. }
  4333. solution := models.DialysisSolution{
  4334. RegistrarsId: adminUserInfo.AdminUser.Id,
  4335. UserOrgId: adminUserInfo.Org.Id,
  4336. Doctor: prescription_doctor,
  4337. PatientId: id,
  4338. ModeId: mode_id,
  4339. DialysisDuration: dialysis_duration,
  4340. PerfusionApparatus: perfusion_apparatus,
  4341. BloodFlowVolume: blood_flow_volume,
  4342. Dewater: dewater_amount,
  4343. DisplaceLiqui: displace_liqui,
  4344. ReplacementWay: replacement_way,
  4345. Anticoagulant: anticoagulant,
  4346. AnticoagulantShouji: anticoagulant_shouji,
  4347. AnticoagulantWeichi: anticoagulant_weichi,
  4348. AnticoagulantZongliang: anticoagulant_zongliang,
  4349. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4350. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4351. Kalium: kalium,
  4352. Sodium: sodium,
  4353. Calcium: calcium,
  4354. Bicarbonate: bicarbonate,
  4355. Glucose: glucose,
  4356. // DryWeight: dry_weight,
  4357. DialysateFlow: dialysate_flow,
  4358. DialysateTemperature: dialysate_temperature,
  4359. Conductivity: conductivity,
  4360. Remark: remark,
  4361. Status: 1,
  4362. CreatedTime: time.Now().Unix(),
  4363. UpdatedTime: time.Now().Unix(),
  4364. DialysisDurationMinute: dialysisDurationMinute,
  4365. DialysisDurationHour: dialysisDurationHour,
  4366. TargetUltrafiltration: targetUltrafiltration,
  4367. DialysateFormulation: dialysateFormulation,
  4368. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4369. BodyFluid: body_fluid,
  4370. SpecialMedicine: special_medicine,
  4371. SpecialMedicineOther: special_medicine_other,
  4372. DisplaceLiquiPart: displace_liqui_part,
  4373. DisplaceLiquiValue: displace_liqui_value,
  4374. BloodAccess: blood_access,
  4375. Ultrafiltration: ultrafiltration,
  4376. BodyFluidOther: body_fluid_other,
  4377. ReplacementTotal: replacement_total,
  4378. TargetKtv: target_ktv,
  4379. DialysisDialyszers: dialysis_dialyszers,
  4380. DialysisIrrigation: dialysis_irrigation,
  4381. HemodialysisPipelines: hemodialysis_pipelines,
  4382. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4383. PunctureNeedle: puncture_needle,
  4384. PunctureNeedleCount: puncture_needle_count,
  4385. Epo: epo,
  4386. EpoCount: epo_count,
  4387. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4388. PreImpulse: impulse,
  4389. SolutionStatus: 1,
  4390. DialysisRemark: dialysis_remark,
  4391. PrescribingNumber: prescribing_number,
  4392. PrescriptionSodium: prescription_sodium,
  4393. StartSodium: start_sodium,
  4394. SodiumCurve: sodium_curve,
  4395. TreatmentRemark: treatment_remark,
  4396. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4397. DialysisFluidFlow: dialysis_fluid_flow,
  4398. PrescriptionWater: prescription_water,
  4399. DialysisStrainer: dialysis_strainer,
  4400. Chaptalization: chaptalization,
  4401. WashingTime: washing_time,
  4402. WarshCount: warsh_count,
  4403. BloodAccessPartId: blood_access_part_id,
  4404. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4405. Dialyzate: dialyzate,
  4406. DialysisDialyszersId: dialysis_dialyszers_id,
  4407. DialysisIrrigationId: dialysis_irrigation_id,
  4408. DialysisStrainerId: dialysis_strainer_id,
  4409. FirstSuper: fisrt_sup,
  4410. IsSequential: is_sequen,
  4411. Conduct: conduct,
  4412. }
  4413. //针对河间咸的
  4414. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4415. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4416. solution.DisplaceLiquiPart = 0
  4417. solution.DisplaceLiquiValue = 0
  4418. }
  4419. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4420. prescription.DisplaceLiquiPart = 0
  4421. prescription.DisplaceLiquiValue = 0
  4422. }
  4423. }
  4424. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4425. if solution.PrescribingNumber == 0 {
  4426. solution.PrescribingNumber = 1
  4427. }
  4428. if prescription.PrescribingNumber == 0 {
  4429. prescription.PrescribingNumber = 1
  4430. }
  4431. if solution.PrescribingNumber == 0 && id == 14682 {
  4432. solution.PrescribingNumber = 2
  4433. }
  4434. if solution.PrescribingNumber == 0 && id == 18560 {
  4435. solution.PrescribingNumber = 2
  4436. }
  4437. if prescription.PrescribingNumber == 0 && id == 14682 {
  4438. prescription.PrescribingNumber = 2
  4439. }
  4440. if prescription.PrescribingNumber == 0 && id == 18560 {
  4441. prescription.PrescribingNumber = 2
  4442. }
  4443. }
  4444. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4445. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 || adminUserInfo.Org.Id == 10766 {
  4446. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4447. if len(monitorList) > 0 {
  4448. var ultrafiltration_rate float64
  4449. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4450. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4451. var replacement_rate float64
  4452. if adminUserInfo.Org.Id == 10721 {
  4453. //乘10 除10是为了保留一位小数
  4454. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4455. }
  4456. if adminUserInfo.Org.Id == 9478 {
  4457. //乘10 除10是为了保留一位小数
  4458. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4459. }
  4460. if adminUserInfo.Org.Id == 10766 {
  4461. //乘10 除10是为了保留一位小数
  4462. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4463. }
  4464. var firstOpeateTime = monitorList[0].OperateTime
  4465. for _, item := range monitorList {
  4466. //超滤率
  4467. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4468. //置换率
  4469. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4470. //超滤量
  4471. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4472. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4473. //置换量
  4474. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4475. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4476. }
  4477. }
  4478. }
  4479. //记录日志
  4480. byterequest, _ := json.Marshal(prescription)
  4481. prescriptionLog := models.XtDialysisPrescriptionLog{
  4482. UserOrgId: prescription.UserOrgId,
  4483. Ctime: time.Now().Unix(),
  4484. Mtime: 0,
  4485. ErrLog: string(byterequest),
  4486. AdminUserId: adminUserInfo.AdminUser.Id,
  4487. RecordDate: prescription.RecordDate,
  4488. PatientId: prescription.PatientId,
  4489. Source: "手机端新增长期处方",
  4490. Status: 1,
  4491. }
  4492. service.CreatePrescriptionLog(prescriptionLog)
  4493. finish := models.XtDialysisFinish{
  4494. IsFinish: 1,
  4495. UserOrgId: adminUserInfo.Org.Id,
  4496. Status: 1,
  4497. Ctime: time.Now().Unix(),
  4498. Mtime: 0,
  4499. Module: 1,
  4500. RecordDate: recordDate.Unix(),
  4501. Sourse: 1,
  4502. PatientId: id,
  4503. }
  4504. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4505. if dialysisFinish.ID == 0 {
  4506. service.CreateDialysisFinish(finish)
  4507. }
  4508. //获取最新1条
  4509. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4510. //更新状态
  4511. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4512. //长沙南雅医院,自动生成抗凝剂的临时处方
  4513. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4514. if prescribing_number == 0 {
  4515. prescribing_number = 1
  4516. }
  4517. advice := models.DoctorAdvice{
  4518. UserOrgId: adminUserInfo.Org.Id,
  4519. PatientId: id,
  4520. GroupNo: 0,
  4521. AdviceType: 2,
  4522. RecordDate: recordDate.Unix(),
  4523. AdviceDate: recordDate.Unix(),
  4524. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4525. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4526. AdviceDesc: "",
  4527. ReminderDate: 0,
  4528. SingleDose: prescription.AnticoagulantZongliang,
  4529. SingleDoseUnit: "iu",
  4530. DrugSpec: 0,
  4531. DrugSpecUnit: "",
  4532. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4533. PrescribingNumberUnit: "支",
  4534. DeliveryWay: "静脉注射",
  4535. ExecutionFrequency: "上机前",
  4536. AdviceDoctor: 0,
  4537. Status: 1,
  4538. CreatedTime: time.Now().Unix(),
  4539. UpdatedTime: time.Now().Unix(),
  4540. IsPrescription: 1,
  4541. ExecutionState: 2,
  4542. StopState: 2,
  4543. IsSettle: 2,
  4544. }
  4545. // 查询排班信息
  4546. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4547. if schedulePatient.ID > 0 {
  4548. if schedulePatient.ScheduleType == 1 {
  4549. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4550. }
  4551. if schedulePatient.ScheduleType == 2 {
  4552. advice.StartTime = recordDate.Unix() + 9*60*60
  4553. }
  4554. }
  4555. // 抗凝剂名称
  4556. switch anticoagulant {
  4557. case 1:
  4558. advice.AdviceName = "无肝素"
  4559. break
  4560. case 2:
  4561. advice.AdviceName = "普通肝素"
  4562. break
  4563. case 3:
  4564. advice.AdviceName = "低分子肝素"
  4565. break
  4566. case 4:
  4567. advice.AdviceName = "阿加曲班"
  4568. break
  4569. case 5:
  4570. advice.AdviceName = "枸橼酸钠"
  4571. break
  4572. case 6:
  4573. advice.AdviceName = "低分子肝素钙"
  4574. break
  4575. case 7:
  4576. advice.AdviceName = "低分子肝素钠"
  4577. break
  4578. case 8:
  4579. advice.AdviceName = "依诺肝素"
  4580. break
  4581. case 9:
  4582. advice.AdviceName = "达肝素"
  4583. break
  4584. case 10:
  4585. advice.AdviceName = "体外抗凝"
  4586. break
  4587. case 11:
  4588. advice.AdviceName = "那曲肝素"
  4589. break
  4590. case 12:
  4591. advice.AdviceName = "无抗凝剂"
  4592. break
  4593. }
  4594. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4595. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4596. advice.AdviceDoctor = appRole.AdminUserId
  4597. }
  4598. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4599. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4600. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4601. advice.AdviceName = "低分子肝素钠注射液"
  4602. // 修改患者临时医嘱里的抗凝剂医嘱
  4603. advice.ID = advicePrescription.ID
  4604. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4605. } else {
  4606. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4607. advice.AdviceName = "低分子肝素钠注射液"
  4608. service.CreateDoctorAdvice(&advice)
  4609. }
  4610. }
  4611. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4612. redis := service.RedisClient()
  4613. defer redis.Close()
  4614. //清空key 值
  4615. redis.Set(key, "", time.Second)
  4616. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4617. redis.Set(keyOne, "", time.Second)
  4618. }
  4619. //获取key,清空redis
  4620. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4621. redis := service.RedisClient()
  4622. defer redis.Close()
  4623. //清空key 值
  4624. redis.Set(key, "", time.Second)
  4625. //清空长期医嘱的key
  4626. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4627. redis.Set(soulution_key, "", time.Second)
  4628. //查询最近透析准备表里是否存在 透析器 灌流器
  4629. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4630. redis.Set(keyOne, "", time.Second)
  4631. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4632. redis.Set(keyTwo, "", time.Second)
  4633. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4634. redis.Set(keyThree, "", time.Second)
  4635. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4636. redis.Set(keyFour, "", time.Second)
  4637. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4638. //
  4639. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4640. //
  4641. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4642. //if len(mation)>0{
  4643. // for _, item := range splitStr {
  4644. // for _,it := range mation{
  4645. // if(item == it.SpecificationName){
  4646. //
  4647. // //查询最近一次的透析器
  4648. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4649. //
  4650. // if errcode == gorm.ErrRecordNotFound{
  4651. // //插入数据
  4652. // prepare := models.DialysisBeforePrepare{
  4653. // UserOrgId: adminUserInfo.Org.Id,
  4654. // PatientId: id,
  4655. // RecordDate: recordDate.Unix(),
  4656. // GoodTypeId: it.GoodTypeId,
  4657. // GoodId: it.ID,
  4658. // Count: 1,
  4659. // Ctime: time.Now().Unix(),
  4660. // Creater: adminUserInfo.AdminUser.Id,
  4661. // Status:1,
  4662. //
  4663. // }
  4664. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4665. // fmt.Println("",errcode)
  4666. // }
  4667. // }
  4668. // }
  4669. //
  4670. // }
  4671. //
  4672. // for _, item := range splitIrrigation {
  4673. // for _,it := range mation{
  4674. // if(item == it.SpecificationName){
  4675. // //查询最近一次的透析器
  4676. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4677. // if errcode == gorm.ErrRecordNotFound{
  4678. // //插入数据
  4679. // prepare := models.DialysisBeforePrepare{
  4680. // UserOrgId: adminUserInfo.Org.Id,
  4681. // PatientId: id,
  4682. // RecordDate: recordDate.Unix(),
  4683. // GoodTypeId: it.GoodTypeId,
  4684. // GoodId: it.ID,
  4685. // Count: 1,
  4686. // Ctime: time.Now().Unix(),
  4687. // Creater: adminUserInfo.AdminUser.Id,
  4688. // Status:1,
  4689. //
  4690. // }
  4691. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4692. // fmt.Println(errcode)
  4693. // }
  4694. // }
  4695. // }
  4696. // }
  4697. //}
  4698. c.ServeSuccessJSON(map[string]interface{}{
  4699. "solution": &solution,
  4700. "prescription": &prescription,
  4701. })
  4702. }
  4703. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4704. patient, _ := c.GetInt64("patient", 0)
  4705. adminUserInfo := c.GetMobileAdminUserInfo()
  4706. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4707. c.ServeSuccessJSON(map[string]interface{}{
  4708. "receiveTreatmentAsses": receiveTreatmentAsses,
  4709. })
  4710. }
  4711. func (this *DialysisAPIController) PostSignInfo() {
  4712. patientID, _ := this.GetInt64("patient_id")
  4713. recordDateStr := this.GetString("date")
  4714. if patientID <= 0 {
  4715. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4716. return
  4717. }
  4718. if len(recordDateStr) == 0 {
  4719. recordDateStr = time.Now().Format("2006-01-02")
  4720. }
  4721. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4722. if parseDateErr != nil {
  4723. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4724. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4725. return
  4726. }
  4727. adminInfo := this.GetMobileAdminUserInfo()
  4728. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4729. if err != nil {
  4730. this.ErrorLog("签名失败:%v", err)
  4731. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4732. return
  4733. }
  4734. this.ServeSuccessJSON(map[string]interface{}{
  4735. "doctor_id": adminInfo.AdminUser.Id,
  4736. })
  4737. }
  4738. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4739. patientID, _ := this.GetInt64("patient_id")
  4740. adminInfo := this.GetMobileAdminUserInfo()
  4741. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4742. this.ServeSuccessJSON(map[string]interface{}{
  4743. "monitor": record,
  4744. })
  4745. }
  4746. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4747. thisTime := time.Now()
  4748. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4749. timeLayout := "2006-01-02 15:04:05"
  4750. loc, _ := time.LoadLocation("Local")
  4751. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4752. theAssessmentDateTime := theStartTime.Unix()
  4753. patientID, _ := this.GetInt64("patient_id")
  4754. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4755. adminInfo := this.GetMobileAdminUserInfo()
  4756. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4757. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4758. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4759. var ultrafiltration_rate float64
  4760. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4761. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4762. fmt.Println(evaluation)
  4763. fmt.Println("prescription.ID", prescription.ID)
  4764. if prescription.ID > 0 {
  4765. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4766. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4767. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4768. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4769. record.UltrafiltrationRate = ultrafiltration_rate
  4770. }
  4771. //重庆塘坝卫生院
  4772. if adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 {
  4773. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4774. record.UltrafiltrationRate = ultrafiltration_rate
  4775. }
  4776. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4777. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4778. record.UltrafiltrationRate = ultrafiltration_rate
  4779. }
  4780. if adminInfo.Org.Id == 10510 {
  4781. record.UltrafiltrationRate = 0
  4782. }
  4783. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4784. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4785. record.UltrafiltrationRate = ultrafiltration_rate
  4786. }
  4787. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4788. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4789. record.UltrafiltrationRate = ultrafiltration_rate
  4790. }
  4791. // 只针对方济医院
  4792. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4793. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4794. ultrafiltration_rate = value
  4795. record.UltrafiltrationRate = ultrafiltration_rate
  4796. }
  4797. if template.TemplateId == 41 || template.TemplateId == 47 {
  4798. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4799. record.UltrafiltrationRate = ultrafiltration_rate
  4800. }
  4801. if template.TemplateId == 43 {
  4802. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4803. record.UltrafiltrationRate = ultrafiltration_rate
  4804. }
  4805. if template.TemplateId == 46 || template.TemplateId == 54 {
  4806. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4807. record.UltrafiltrationRate = ultrafiltration_rate
  4808. }
  4809. 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 {
  4810. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4811. record.UltrafiltrationRate = ultrafiltration_rate
  4812. }
  4813. if adminInfo.Org.Id == 10469 {
  4814. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4815. record.UltrafiltrationRate = ultrafiltration_rate
  4816. }
  4817. if adminInfo.Org.Id == 10667 {
  4818. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4819. record.UltrafiltrationRate = ultrafiltration_rate
  4820. }
  4821. if adminInfo.Org.Id == 10471 {
  4822. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4823. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4824. }
  4825. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4826. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4827. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4828. }
  4829. if adminInfo.Org.Id == 10751 {
  4830. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4831. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4832. }
  4833. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4834. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4835. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4836. }
  4837. if adminInfo.Org.Id == 10721 {
  4838. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4839. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4840. }
  4841. if adminInfo.Org.Id == 10766 {
  4842. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4843. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4844. }
  4845. if adminInfo.Org.Id == 10757 {
  4846. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4847. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4848. }
  4849. if adminInfo.Org.Id == 10752 {
  4850. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4851. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4852. }
  4853. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4854. record.UltrafiltrationRate = 0
  4855. }
  4856. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4857. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4858. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4859. }
  4860. if adminInfo.Org.Id == 10206 {
  4861. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4862. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4863. }
  4864. //湘潭爱心美白石
  4865. if adminInfo.Org.Id == 9850 {
  4866. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4867. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4868. }
  4869. if adminInfo.Org.Id == 9919 {
  4870. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4871. record.UltrafiltrationRate = math.Floor(ultrafiltration_rate / 1000)
  4872. }
  4873. //if template.TemplateId == 47 {
  4874. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4875. // record.UltrafiltrationRate = ultrafiltration_rate
  4876. //}
  4877. }
  4878. }
  4879. // record.UltrafiltrationRate = ultrafiltration_rate
  4880. record.UltrafiltrationVolume = 0
  4881. 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
  4882. if ultrafiltration_rate > 0 {
  4883. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4884. record.UltrafiltrationVolume = value
  4885. }
  4886. }
  4887. 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
  4888. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4889. if adminInfo.Org.Id != 10735 {
  4890. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4891. record.UltrafiltrationVolume = ultrafiltration_volume
  4892. }
  4893. //胶州少海医院
  4894. if adminInfo.Org.Id == 10735 {
  4895. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4896. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4897. var ultrafiltration_rate_one = math.Floor(prescription.TargetUltrafiltration*1000/float64(totalMin)*60*1000) / 1000
  4898. if lastMonitorRecordList.ID > 0 {
  4899. record.UltrafiltrationRate = ultrafiltration_rate_one
  4900. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4901. record.UltrafiltrationVolume = ultrafiltration_volume
  4902. } else {
  4903. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4904. record.UltrafiltrationVolume = ultrafiltration_volume
  4905. }
  4906. }
  4907. }
  4908. }
  4909. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4910. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4911. record.UltrafiltrationVolume = ultrafiltration_volume
  4912. }
  4913. //长沙南雅
  4914. 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 {
  4915. if ultrafiltration_rate > 0 {
  4916. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4917. record.UltrafiltrationVolume = ultrafiltration_volume
  4918. }
  4919. }
  4920. if adminInfo.Org.Id == 10471 {
  4921. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4922. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4923. }
  4924. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4925. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4926. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4927. }
  4928. if adminInfo.Org.Id == 10751 {
  4929. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4930. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4931. }
  4932. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4933. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4934. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4935. }
  4936. //长沙南雅累计血容量自动计算
  4937. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4938. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4939. //}
  4940. if template.TemplateId == 47 || template.TemplateId == 54 {
  4941. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4942. }
  4943. if adminInfo.Org.Id == 10510 {
  4944. record.UltrafiltrationVolume = 0
  4945. }
  4946. 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 {
  4947. if ultrafiltration_rate > 0 {
  4948. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4949. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4950. }
  4951. }
  4952. //古镇乐生
  4953. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4954. if ultrafiltration_rate > 0 {
  4955. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4956. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4957. }
  4958. }
  4959. if adminInfo.Org.Id == 9919 {
  4960. if ultrafiltration_rate > 0 {
  4961. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4962. record.UltrafiltrationVolume = math.Floor(ultrafiltration_volume / 1000)
  4963. }
  4964. }
  4965. if adminInfo.Org.Id == 10206 {
  4966. if ultrafiltration_rate > 0 {
  4967. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4968. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4969. }
  4970. }
  4971. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10757 || adminInfo.Org.Id == 10290 {
  4972. var replacement_rate float64
  4973. var displacement_quantity float64
  4974. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4975. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4976. record.ReplacementRate = replacement_rate
  4977. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4978. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4979. record.DisplacementQuantity = displacement_quantity
  4980. }
  4981. if adminInfo.Org.Id == 10766 {
  4982. var replacement_rate float64
  4983. var displacement_quantity float64
  4984. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4985. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  4986. record.ReplacementRate = replacement_rate
  4987. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4988. record.DisplacementQuantity = displacement_quantity
  4989. }
  4990. if adminInfo.Org.Id == 9478 {
  4991. var replacement_rate float64
  4992. var displacement_quantity float64
  4993. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4994. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  4995. record.ReplacementRate = replacement_rate
  4996. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4997. record.DisplacementQuantity = displacement_quantity
  4998. }
  4999. if adminInfo.Org.Id == 10752 {
  5000. var replacement_rate float64
  5001. var displacement_quantity float64
  5002. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5003. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5004. record.ReplacementRate = replacement_rate
  5005. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5006. record.DisplacementQuantity = displacement_quantity
  5007. }
  5008. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 || adminInfo.Org.Id == 10766 {
  5009. var replacement_rate float64
  5010. var displacement_quantity float64
  5011. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5012. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5013. record.ReplacementRate = replacement_rate
  5014. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5015. record.DisplacementQuantity = displacement_quantity
  5016. }
  5017. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  5018. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5019. record.UltrafiltrationVolume = ultrafiltration_volume
  5020. }
  5021. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10744 {
  5022. var replacement_rate float64
  5023. var displacement_quantity float64
  5024. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5025. if totalMin == 0 {
  5026. totalMin = 240
  5027. }
  5028. if prescription.DisplaceLiquiValue == 0 {
  5029. prescription.ReplacementTotal = 32
  5030. }
  5031. //乘10 除10是为了保留一位小数
  5032. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  5033. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  5034. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5035. record.DisplacementQuantity = displacement_quantity
  5036. }
  5037. if adminInfo.Org.Id == 9850 {
  5038. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5039. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5040. }
  5041. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  5042. fisrtMonitorRecordList, _ := service.GetFisrtMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  5043. this.ServeSuccessJSON(map[string]interface{}{
  5044. "monitor": record,
  5045. "lastMonitorRecordList": lastMonitorRecordList,
  5046. "fisrtMonitorRecordList": fisrtMonitorRecordList,
  5047. })
  5048. }
  5049. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  5050. record_id, _ := this.GetInt64("id")
  5051. nurseID, _ := this.GetInt64("start_nurse")
  5052. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  5053. bedID, _ := this.GetInt64("bed")
  5054. start_time := this.GetString("start_time")
  5055. schedual_type, _ := this.GetInt64("schedual_type")
  5056. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  5057. change_nurse, _ := this.GetInt64("change_nurse")
  5058. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  5059. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  5060. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  5061. patient_id, _ := this.GetInt64("patient_id")
  5062. record_date, _ := this.GetInt64("record_date")
  5063. puncture_needle := this.GetString("puncture_needle")
  5064. puncture_way := this.GetString("puncture_way")
  5065. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  5066. dialysis_irrigation := this.GetString("dialysis_irrigation")
  5067. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  5068. nuclein_date_str := this.GetString("nuclein_date_str")
  5069. order_remark := this.GetString("order_remark")
  5070. schedule_remark := this.GetString("schedule_remark")
  5071. catheter_operation := this.GetString("catheter_operation")
  5072. blood_flow_volume := this.GetString("blood_flow_volume")
  5073. blood_drawing, _ := this.GetInt64("blood_drawing")
  5074. dialysis_strainer := this.GetString("dialysis_strainer")
  5075. if record_id == 0 {
  5076. this.ErrorLog("id:%v", record_id)
  5077. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5078. return
  5079. }
  5080. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5081. if parseStartDateErr != nil {
  5082. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  5083. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5084. return
  5085. }
  5086. adminUserInfo := this.GetMobileAdminUserInfo()
  5087. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5088. if getNurseErr != nil {
  5089. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5090. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5091. return
  5092. } else if nurse == nil {
  5093. this.ErrorLog("护士不存在")
  5094. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5095. return
  5096. }
  5097. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  5098. //if getNurseErr != nil {
  5099. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  5100. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5101. // return
  5102. //} else if nurse == nil {
  5103. // this.ErrorLog("护士不存在")
  5104. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5105. // return
  5106. //}
  5107. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  5108. if getDeviceNumberErr != nil {
  5109. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  5110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5111. return
  5112. } else if deviceNumber == nil {
  5113. this.ErrorLog("床位号不存在")
  5114. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5115. return
  5116. }
  5117. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  5118. //
  5119. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  5120. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5121. // if getPermissionErr != nil {
  5122. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5123. // return
  5124. // } else if headNursePermission == nil {
  5125. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5126. // return
  5127. // }
  5128. //}
  5129. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  5130. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  5131. timeLayout := "2006-01-02 15:04:05"
  5132. loc, _ := time.LoadLocation("Local")
  5133. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5134. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  5135. schedulestartTime := theStartTime.Unix()
  5136. scheduleendTime := theEndTime.Unix()
  5137. var theNucleinDate int64
  5138. timeLayoutOne := "2006-01-02"
  5139. if len(nuclein_date_str) > 0 {
  5140. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  5141. if err != nil {
  5142. utils.ErrorLog(err.Error())
  5143. }
  5144. theNucleinDate = theTime.Unix()
  5145. }
  5146. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  5147. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  5148. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5149. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  5150. if err == gorm.ErrRecordNotFound { //空床位
  5151. // 修改了床位逻辑
  5152. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5153. if daySchedule.ID > 0 {
  5154. //daySchedule.BedId = bedID
  5155. //daySchedule.PartitionId = deviceNumber.ZoneID
  5156. //daySchedule.ScheduleType = schedual_type
  5157. //daySchedule.UpdatedTime = time.Now().Unix()
  5158. //err := service.UpdateSchedule(&daySchedule)
  5159. xtSchedule := models.Schedule{
  5160. PartitionId: deviceNumber.ZoneID,
  5161. BedId: bedID,
  5162. ScheduleType: schedual_type,
  5163. UpdatedTime: time.Now().Unix(),
  5164. }
  5165. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5166. if err != nil {
  5167. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5168. return
  5169. }
  5170. }
  5171. } else if err == nil {
  5172. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  5173. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5174. if daySchedule.ID > 0 {
  5175. //daySchedule.BedId = bedID
  5176. //daySchedule.PartitionId = deviceNumber.ZoneID
  5177. //
  5178. //daySchedule.ScheduleType = schedual_type
  5179. //daySchedule.UpdatedTime = time.Now().Unix()
  5180. //err := service.UpdateSchedule(&daySchedule)
  5181. xtSchedule := models.Schedule{
  5182. PartitionId: deviceNumber.ZoneID,
  5183. BedId: bedID,
  5184. ScheduleType: schedual_type,
  5185. UpdatedTime: time.Now().Unix(),
  5186. }
  5187. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5188. if err != nil {
  5189. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5190. return
  5191. }
  5192. }
  5193. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  5194. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  5195. return
  5196. }
  5197. } else if err != nil {
  5198. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5199. return
  5200. }
  5201. }
  5202. dialysisRecord := &models.DialysisOrder{
  5203. ID: record_id,
  5204. UserOrgId: adminUserInfo.Org.Id,
  5205. BedID: bedID,
  5206. StartNurse: nurseID,
  5207. StartTime: startDate.Unix(),
  5208. PunctureNurse: puncture_nurse,
  5209. Creator: adminUserInfo.AdminUser.Id,
  5210. Modifier: adminUserInfo.AdminUser.Id,
  5211. WashpipeNurse: washpipe_nurse,
  5212. SchedualType: schedual_type,
  5213. ChangeNurse: change_nurse,
  5214. DifficultPunctureNurse: difficult_puncture_nurse,
  5215. NewFistulaNurse: new_fistula_nurse,
  5216. QualityNurseId: quality_nurse_id,
  5217. PunctureNeedle: puncture_needle,
  5218. PunctureWay: puncture_way,
  5219. DialysisDialyszers: dialysis_dialyszers,
  5220. DialysisIrrigation: dialysis_irrigation,
  5221. BloodAccessId: blood_access_id,
  5222. NucleinDate: theNucleinDate,
  5223. OrderRemark: order_remark,
  5224. ScheduleRemark: schedule_remark,
  5225. CatheterOperation: catheter_operation,
  5226. BloodFlowVolume: blood_flow_volume,
  5227. BloodDrawing: blood_drawing,
  5228. DialysisStrainer: dialysis_strainer,
  5229. }
  5230. _, prescription := service.FindDialysisPrescriptionByReordDate(patient_id, record_date, adminUserInfo.Org.Id)
  5231. if prescription.ID > 0 {
  5232. var endTime int64
  5233. endTime = dialysisRecord.StartTime + prescription.DialysisDurationHour*3600 + prescription.DialysisDurationMinute*60
  5234. dialysisRecord.EndTime = endTime
  5235. }
  5236. //修改床位号需要重新消毒
  5237. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  5238. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5239. //查询第一条监测
  5240. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5241. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  5242. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  5243. redis := service.RedisClient()
  5244. //清空key 值
  5245. redis.Set(key, "", time.Second)
  5246. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  5247. redis.Set(keyOne, "", time.Second)
  5248. defer redis.Close()
  5249. }
  5250. // 查询信息规挡的设置天数
  5251. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5252. if infor.ID > 0 && infor.WeekDay > 0 {
  5253. var cha_time int64
  5254. timeNowStr := time.Now().Format("2006-01-02")
  5255. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5256. //今日的日期减去设置的日期
  5257. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5258. if cha_time >= record_date {
  5259. //查询审核是否允许
  5260. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  5261. //申请状态不允许的情况 拒绝修改
  5262. if infor.ApplicationStatus != 1 {
  5263. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5264. return
  5265. }
  5266. }
  5267. }
  5268. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  5269. //修改床位后重新生成消毒计划
  5270. if adminUserInfo.Org.Id == 10340 {
  5271. //根据床位号获取设备型号
  5272. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5273. //查询使用消毒最后一条消毒记录
  5274. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  5275. fmt.Println("err", err)
  5276. if err == gorm.ErrRecordNotFound {
  5277. //查找排班
  5278. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  5279. //查询改设备是否有消毒计划
  5280. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  5281. //根据床位号获取设备id
  5282. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5283. //查询病人信息
  5284. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  5285. var con = ""
  5286. if patients.IsInfectious == 0 {
  5287. con = ""
  5288. }
  5289. if patients.IsInfectious == 1 {
  5290. con = "无"
  5291. }
  5292. if patients.IsInfectious == 2 {
  5293. con = "有"
  5294. }
  5295. if errcode == nil {
  5296. var end_time int64
  5297. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  5298. //新增消毒
  5299. information := models.DeviceInformation{
  5300. Date: dialysisRecord.DialysisDate,
  5301. Zone: dialysisRecord.ZoneId,
  5302. Class: dialysisRecord.SchedualType,
  5303. BedNumber: dialysisRecord.BedID,
  5304. PatientId: dialysisRecord.PatientId,
  5305. DialysisMode: scheduleByPatient.ModeId,
  5306. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  5307. Disinfection: 1,
  5308. DialysisConcentration: 1,
  5309. DisinfectionStatus: 1,
  5310. Move: 1,
  5311. UserOrgId: dialysisRecord.UserOrgId,
  5312. DisinfectType: plan.Way,
  5313. DisinfectantType: plan.MachineDisinfectant,
  5314. FluidPath: plan.DisinfectanWay, //液路消毒方式
  5315. Disinfectant: plan.Disinfectant,
  5316. Ctime: time.Now().Unix(),
  5317. Status: 1,
  5318. SignName: nurseID,
  5319. EquimentId: addmacher.ID,
  5320. DisinfectionResidue: 2,
  5321. Bed: addmacher.BedNumber,
  5322. StartTime: dialysisRecord.StartTime,
  5323. EndTime: dialysisRecord.EndTime,
  5324. Contagion: con,
  5325. WeightLoss: 0,
  5326. Hyperfiltratio: 0,
  5327. DialysisHour: "",
  5328. MachineRun: 1,
  5329. DisinfecStartime: dialysisRecord.EndTime,
  5330. DisinfecEndtime: end_time,
  5331. }
  5332. err := service.CreateInformationTwo(&information)
  5333. fmt.Println("报错", err)
  5334. }
  5335. }
  5336. }
  5337. order, _ := service.GetLastPatientOrder(record_id)
  5338. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  5339. redis := service.RedisClient()
  5340. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  5341. redis.Set(key, "", time.Second)
  5342. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5343. //清空key 值
  5344. redis.Set(keyOne, "", time.Second)
  5345. scheduleDateStartOne := startDate.Format("2006-01-02")
  5346. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5347. redis.Set(keyTwo, "", time.Second)
  5348. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  5349. redis.Set(keyThree, "", time.Second)
  5350. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5351. redis.Set(keyFour, "", time.Second)
  5352. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  5353. redis.Set(keyFive, "", time.Second)
  5354. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  5355. redis.Set(keySix, "", time.Second)
  5356. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  5357. redis.Set(keySeven, "", time.Second)
  5358. if updateErr != nil {
  5359. this.ErrorLog("修改上机失败:%v", updateErr)
  5360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5361. return
  5362. }
  5363. if updateErr == nil {
  5364. if tempDialysisRecord.Stage == 2 {
  5365. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5366. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5367. fmt.Println(value)
  5368. a, b := math.Modf(value)
  5369. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5370. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5371. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5372. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5373. redis := service.RedisClient()
  5374. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  5375. redis.Set(key, "", time.Second)
  5376. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  5377. redis.Set(keyOne, "", time.Second)
  5378. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5379. //清空key 值
  5380. redis.Set(keySix, "", time.Second)
  5381. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5382. redis.Set(keySeven, "", time.Second)
  5383. redis.Close()
  5384. if updateAssessmentErr != nil {
  5385. utils.ErrorLog("%v", updateAssessmentErr)
  5386. }
  5387. }
  5388. }
  5389. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5390. this.ServeSuccessJSON(map[string]interface{}{
  5391. "dialysis_order": dialysisRecords,
  5392. })
  5393. }
  5394. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5395. record_id, _ := c.GetInt64("id")
  5396. nurseID, _ := c.GetInt64("nurse")
  5397. end_time := c.GetString("end_time")
  5398. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  5399. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  5400. catheter := c.GetString("catheter")
  5401. cruor := c.GetString("cruor")
  5402. mission := c.GetString("mission")
  5403. condenser := c.GetString("condenser")
  5404. if record_id <= 0 || nurseID <= 0 {
  5405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5406. return
  5407. }
  5408. adminUserInfo := c.GetMobileAdminUserInfo()
  5409. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5410. if getNurseErr != nil {
  5411. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5413. return
  5414. } else if nurse == nil {
  5415. c.ErrorLog("护士不存在")
  5416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5417. return
  5418. }
  5419. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5420. if parseEndDateErr != nil {
  5421. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5423. return
  5424. }
  5425. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5426. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5427. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5428. // if getPermissionErr != nil {
  5429. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5430. // return
  5431. // } else if headNursePermission == nil {
  5432. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5433. // return
  5434. // }
  5435. //}
  5436. // 查询信息规挡的设置天数
  5437. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5438. if infor.ID > 0 {
  5439. var cha_time int64
  5440. timeNowStr := time.Now().Format("2006-01-02")
  5441. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5442. //今日的日期减去设置的日期
  5443. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5444. if cha_time >= tempDialysisRecords.DialysisDate {
  5445. //查询审核是否允许
  5446. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5447. //申请状态不允许的情况 拒绝修改
  5448. if infor.ApplicationStatus != 1 {
  5449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5450. return
  5451. }
  5452. }
  5453. }
  5454. dialysisRecord := &models.DialysisOrder{
  5455. ID: record_id,
  5456. UserOrgId: adminUserInfo.Org.Id,
  5457. EndTime: endDate.Unix(),
  5458. FinishNurse: nurseID,
  5459. FinishModifier: adminUserInfo.AdminUser.Id,
  5460. PuncturePointHaematoma: puncture_point_haematoma,
  5461. BloodAccessInternalFistula: blood_access_internal_fistula,
  5462. Catheter: catheter,
  5463. Cruor: cruor,
  5464. Mission: mission,
  5465. Condenser: condenser,
  5466. }
  5467. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5468. redis := service.RedisClient()
  5469. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5470. //清空key 值
  5471. redis.Set(key, "", time.Second)
  5472. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5473. //清空key 值
  5474. redis.Set(keyOne, "", time.Second)
  5475. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5476. redis.Set(keySeven, "", time.Second)
  5477. redis.Close()
  5478. if updateErr != nil {
  5479. c.ErrorLog("修改下机失败:%v", updateErr)
  5480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5481. return
  5482. }
  5483. if updateErr == nil {
  5484. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5485. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5486. a, b := math.Modf(value)
  5487. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5488. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5489. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5490. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5491. redis := service.RedisClient()
  5492. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5493. redis.Set(keyTen, "", time.Second)
  5494. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5495. redis.Set(keyTwo, "", time.Second)
  5496. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5497. redis.Set(key, "", time.Second)
  5498. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5499. redis.Set(keyThree, "", time.Second)
  5500. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5501. redis.Set(keySeven, "", time.Second)
  5502. defer redis.Close()
  5503. if updateAssessmentErr != nil {
  5504. utils.ErrorLog("%v", updateAssessmentErr)
  5505. }
  5506. }
  5507. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5508. c.ServeSuccessJSON(map[string]interface{}{
  5509. "dialysis_order": dialysisRecords,
  5510. })
  5511. }
  5512. func (c *DialysisAPIController) GetLongAdvice() {
  5513. patient_id, _ := c.GetInt64("id")
  5514. adminUserInfo := c.GetMobileAdminUserInfo()
  5515. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5516. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5517. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5518. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5519. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5520. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5521. c.ServeSuccessJSON(map[string]interface{}{
  5522. "status": "1",
  5523. })
  5524. return
  5525. } else { //开启推送提醒
  5526. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5527. var advice_three []*models.DoctorAdvice
  5528. recordDateStr := time.Now().Format("2006-01-02")
  5529. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5530. nowtime := recordDate.Unix()
  5531. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5532. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5533. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5534. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5535. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5536. for _, advice := range advices {
  5537. if advice.FrequencyType == 3 {
  5538. t := time.Now()
  5539. week := int(t.Weekday())
  5540. fmt.Println(t.Weekday())
  5541. fmt.Println(week)
  5542. switch week {
  5543. case 1:
  5544. if strings.Index(advice.WeekDay, "周一") == -1 {
  5545. advice_three = append(advice_three, advice)
  5546. }
  5547. break
  5548. case 2:
  5549. if strings.Index(advice.WeekDay, "周二") == -1 {
  5550. advice_three = append(advice_three, advice)
  5551. }
  5552. break
  5553. case 3:
  5554. if strings.Index(advice.WeekDay, "周三") == -1 {
  5555. advice_three = append(advice_three, advice)
  5556. }
  5557. break
  5558. case 4:
  5559. if strings.Index(advice.WeekDay, "周四") == -1 {
  5560. advice_three = append(advice_three, advice)
  5561. }
  5562. break
  5563. case 5:
  5564. if strings.Index(advice.WeekDay, "周五") == -1 {
  5565. advice_three = append(advice_three, advice)
  5566. }
  5567. break
  5568. case 6:
  5569. if strings.Index(advice.WeekDay, "周六") == -1 {
  5570. advice_three = append(advice_three, advice)
  5571. }
  5572. break
  5573. case 0:
  5574. if strings.Index(advice.WeekDay, "周日") == -1 {
  5575. advice_three = append(advice_three, advice)
  5576. }
  5577. break
  5578. }
  5579. }
  5580. }
  5581. for _, advice := range advices_two {
  5582. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5583. now := p.Unix()
  5584. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5585. dayStr2 := "-" + dayStr
  5586. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5587. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5588. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5589. for _, ad := range advices {
  5590. advice_three = append(advice_three, ad)
  5591. }
  5592. }
  5593. if err == nil {
  5594. c.ServeSuccessJSON(map[string]interface{}{
  5595. "status": "2",
  5596. "advices": advices,
  5597. "advices_two": RemoveRepeatedElement(advice_three),
  5598. "is_open_remind": config.IsOpenRemind,
  5599. "his_config_open": hisConfig.IsOpen,
  5600. "is_advice_open": is_advice_open.IsAdviceOpen,
  5601. "prescription_open": prescription_open.IsOpen,
  5602. })
  5603. }
  5604. }
  5605. }
  5606. func (c *DialysisAPIController) GetLongAdviceOne() {
  5607. patient_id, _ := c.GetInt64("id")
  5608. startTime := c.GetString("schedule_date")
  5609. timeLayout := "2006-01-02"
  5610. loc, _ := time.LoadLocation("Local")
  5611. var theStartTime int64
  5612. if len(startTime) > 0 {
  5613. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5614. if err != nil {
  5615. utils.ErrorLog(err.Error())
  5616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5617. return
  5618. }
  5619. theStartTime = theTime.Unix()
  5620. }
  5621. adminUserInfo := c.GetMobileAdminUserInfo()
  5622. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5623. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5624. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5625. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5626. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5627. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5628. c.ServeSuccessJSON(map[string]interface{}{
  5629. "status": "1",
  5630. })
  5631. return
  5632. } else { //开启推送提醒
  5633. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5634. var advice_three []*models.DoctorAdvice
  5635. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5636. fmt.Println("theStartTime-----------------------", theStartTime)
  5637. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5638. for _, advice := range advices {
  5639. if advice.FrequencyType == 3 {
  5640. t := time.Now()
  5641. week := int(t.Weekday())
  5642. fmt.Println(t.Weekday())
  5643. fmt.Println(week)
  5644. switch week {
  5645. case 1:
  5646. if strings.Index(advice.WeekDay, "周一") == -1 {
  5647. advice_three = append(advice_three, advice)
  5648. }
  5649. break
  5650. case 2:
  5651. if strings.Index(advice.WeekDay, "周二") == -1 {
  5652. advice_three = append(advice_three, advice)
  5653. }
  5654. break
  5655. case 3:
  5656. if strings.Index(advice.WeekDay, "周三") == -1 {
  5657. advice_three = append(advice_three, advice)
  5658. }
  5659. break
  5660. case 4:
  5661. if strings.Index(advice.WeekDay, "周四") == -1 {
  5662. advice_three = append(advice_three, advice)
  5663. }
  5664. break
  5665. case 5:
  5666. if strings.Index(advice.WeekDay, "周五") == -1 {
  5667. advice_three = append(advice_three, advice)
  5668. }
  5669. break
  5670. case 6:
  5671. if strings.Index(advice.WeekDay, "周六") == -1 {
  5672. advice_three = append(advice_three, advice)
  5673. }
  5674. break
  5675. case 0:
  5676. if strings.Index(advice.WeekDay, "周日") == -1 {
  5677. advice_three = append(advice_three, advice)
  5678. }
  5679. break
  5680. }
  5681. }
  5682. }
  5683. for _, advice := range advices_two {
  5684. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5685. now := p.Unix()
  5686. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5687. dayStr2 := "-" + dayStr
  5688. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5689. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5690. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5691. fmt.Println("advices-==---------------", advices)
  5692. for _, ad := range advices {
  5693. advice_three = append(advice_three, ad)
  5694. }
  5695. }
  5696. if err == nil {
  5697. c.ServeSuccessJSON(map[string]interface{}{
  5698. "status": "2",
  5699. "advices": advices,
  5700. "advices_two": RemoveRepeatedElement(advice_three),
  5701. "is_open_remind": config.IsOpenRemind,
  5702. "his_config_open": hisConfig.IsOpen,
  5703. "is_advice_open": is_advice_open.IsAdviceOpen,
  5704. "prescription_open": prescription_open.IsOpen,
  5705. })
  5706. }
  5707. }
  5708. }
  5709. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5710. newArr = make([]*models.DoctorAdvice, 0)
  5711. for i := 0; i < len(arr); i++ {
  5712. repeat := false
  5713. for j := i + 1; j < len(arr); j++ {
  5714. if arr[i].ID == arr[j].ID {
  5715. repeat = true
  5716. break
  5717. }
  5718. }
  5719. if !repeat {
  5720. newArr = append(newArr, arr[i])
  5721. }
  5722. }
  5723. return
  5724. }
  5725. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5726. patient, _ := c.GetInt64("id", 0)
  5727. groupNo, _ := c.GetInt64("groupno", 0)
  5728. if patient <= 0 {
  5729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5730. return
  5731. }
  5732. adminUserInfo := c.GetMobileAdminUserInfo()
  5733. dataBody := make(map[string]interface{}, 0)
  5734. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5735. if err != nil {
  5736. utils.ErrorLog(err.Error())
  5737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5738. return
  5739. }
  5740. utils.ErrorLog("%v", dataBody)
  5741. timeLayout := "2006-01-02 15:04"
  5742. loc, _ := time.LoadLocation("Local")
  5743. timeLayout2 := "2006-01-02"
  5744. loc2, _ := time.LoadLocation("Local")
  5745. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5746. utils.ErrorLog("advice_type")
  5747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5748. return
  5749. }
  5750. adviceType := int64(2)
  5751. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5752. utils.ErrorLog("advice_date")
  5753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5754. return
  5755. }
  5756. adviceDate, _ := dataBody["advice_date"].(string)
  5757. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5758. AdviceDate := theTime.Unix()
  5759. RecordDate := theTime.Unix()
  5760. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5761. utils.ErrorLog("start_time")
  5762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5763. return
  5764. }
  5765. startTime, _ := dataBody["start_time"].(string)
  5766. if len(startTime) == 0 {
  5767. utils.ErrorLog("len(start_time) == 0")
  5768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5769. return
  5770. }
  5771. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5772. if err != nil {
  5773. utils.ErrorLog(err.Error())
  5774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5775. return
  5776. }
  5777. StartTime := theTime.Unix()
  5778. Remark := ""
  5779. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5780. remark, _ := dataBody["remark"].(string)
  5781. Remark = remark
  5782. }
  5783. var advices []*models.GroupAdvice
  5784. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5785. utils.ErrorLog("advices")
  5786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5787. return
  5788. }
  5789. adviceNames := dataBody["advices"].([]interface{})
  5790. for _, adviceNameMap := range adviceNames {
  5791. adviceNameM := adviceNameMap.(map[string]interface{})
  5792. var advice models.GroupAdvice
  5793. advice.Remark = Remark
  5794. advice.AdviceType = adviceType
  5795. advice.StartTime = StartTime
  5796. advice.AdviceDate = AdviceDate
  5797. advice.RecordDate = RecordDate
  5798. advice.Status = 1
  5799. advice.CreatedTime = time.Now().Unix()
  5800. advice.UpdatedTime = time.Now().Unix()
  5801. advice.StopState = 2
  5802. advice.ExecutionState = 2
  5803. advice.UserOrgId = adminUserInfo.Org.Id
  5804. advice.PatientId = patient
  5805. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5806. advice.IsSettle = 2
  5807. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5808. utils.ErrorLog("advice_name")
  5809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5810. return
  5811. }
  5812. adviceName, _ := adviceNameM["advice_name"].(string)
  5813. if len(adviceName) == 0 {
  5814. utils.ErrorLog("len(advice_name) == 0")
  5815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5816. return
  5817. }
  5818. advice.AdviceName = adviceName
  5819. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5820. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5821. advice.DrugSpec = drugSpec
  5822. }
  5823. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5824. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5825. advice.AdviceDesc = adviceDesc
  5826. }
  5827. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5828. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5829. advice.DrugSpecUnit = drugSpecUnit
  5830. }
  5831. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5832. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5833. // advice.SingleDose = singleDose
  5834. //}
  5835. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5836. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5837. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5838. }
  5839. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5840. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5841. advice.SingleDoseUnit = singleDoseUnit
  5842. }
  5843. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5844. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5845. // advice.PrescribingNumber = prescribingNumber
  5846. //}
  5847. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5848. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5849. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5850. }
  5851. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5852. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5853. advice.PrescribingNumberUnit = prescribingNumberUnit
  5854. }
  5855. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5856. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5857. advice.DeliveryWay = deliveryWay
  5858. }
  5859. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5860. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5861. advice.ExecutionFrequency = executionFrequency
  5862. }
  5863. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5864. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5865. advice.FrequencyType = frequency_type
  5866. }
  5867. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5868. day_count := int64(adviceNameM["day_count"].(float64))
  5869. advice.DayCount = day_count
  5870. }
  5871. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5872. week_day, _ := adviceNameM["week_day"].(string)
  5873. advice.WeekDay = week_day
  5874. }
  5875. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5876. way := int64(adviceNameM["way"].(float64))
  5877. advice.Way = way
  5878. }
  5879. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5880. drug_id := int64(adviceNameM["drug_id"].(float64))
  5881. advice.DrugId = drug_id
  5882. }
  5883. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5884. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5885. advice.DrugNameId = drug_name_id
  5886. }
  5887. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5888. remark, _ := adviceNameM["remark"].(string)
  5889. advice.Remark = remark
  5890. }
  5891. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5892. groupno := int64(adviceNameM["groupno"].(float64))
  5893. advice.GroupNo = groupno
  5894. }
  5895. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5896. template_id, _ := adviceNameM["template_id"].(string)
  5897. advice.TemplateId = template_id
  5898. }
  5899. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5900. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5901. advice.ExecutionFrequency = executionFrequency
  5902. }
  5903. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5904. children := adviceNameM["child"].([]interface{})
  5905. if len(children) > 0 {
  5906. for _, childrenMap := range children {
  5907. childMap := childrenMap.(map[string]interface{})
  5908. var child models.GroupAdvice
  5909. child.Remark = Remark
  5910. child.AdviceType = adviceType
  5911. child.StartTime = StartTime
  5912. child.AdviceDate = AdviceDate
  5913. child.RecordDate = RecordDate
  5914. child.Status = 1
  5915. child.CreatedTime = time.Now().Unix()
  5916. child.UpdatedTime = time.Now().Unix()
  5917. child.StopState = 2
  5918. child.ExecutionState = 2
  5919. child.UserOrgId = adminUserInfo.Org.Id
  5920. child.PatientId = patient
  5921. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5922. child.IsSettle = 1
  5923. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5924. utils.ErrorLog("child advice_name")
  5925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5926. return
  5927. }
  5928. childAdviceName, _ := childMap["advice_name"].(string)
  5929. if len(childAdviceName) == 0 {
  5930. utils.ErrorLog("len(child advice_name) == 0")
  5931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5932. return
  5933. }
  5934. child.AdviceName = childAdviceName
  5935. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5936. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5937. child.AdviceDesc = childAdviceDesc
  5938. }
  5939. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5940. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5941. child.DrugSpec = childDrugSpec
  5942. }
  5943. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5944. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5945. child.DrugSpecUnit = childDrugSpecUnit
  5946. }
  5947. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5948. child.SingleDose = childMap["single_dose"].(float64)
  5949. }
  5950. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5951. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5952. child.SingleDoseUnit = childSingleDoseUnit
  5953. }
  5954. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5955. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5956. }
  5957. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5958. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5959. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5960. }
  5961. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5962. groupno := int64(childMap["groupno"].(float64))
  5963. advice.GroupNo = groupno
  5964. }
  5965. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5966. remark, _ := childMap["remark"].(string)
  5967. child.Remark = remark
  5968. }
  5969. child.DeliveryWay = advice.DeliveryWay
  5970. child.ExecutionFrequency = advice.ExecutionFrequency
  5971. advice.Children = append(advice.Children, &child)
  5972. }
  5973. }
  5974. }
  5975. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5976. if temp_advice.ID == 0 {
  5977. advices = append(advices, &advice)
  5978. }
  5979. }
  5980. if len(advices) > 0 {
  5981. finish := models.XtDialysisFinish{
  5982. IsFinish: 1,
  5983. UserOrgId: adminUserInfo.Org.Id,
  5984. Status: 1,
  5985. Ctime: time.Now().Unix(),
  5986. Mtime: 0,
  5987. Module: 4,
  5988. RecordDate: AdviceDate,
  5989. Sourse: 1,
  5990. PatientId: patient,
  5991. }
  5992. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5993. if dialysisFinish.ID == 0 {
  5994. service.CreateDialysisFinish(finish)
  5995. }
  5996. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5997. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5998. for _, item := range advices {
  5999. byterequest, _ := json.Marshal(item)
  6000. adviceLog := models.XtDoctorAdviceLog{
  6001. UserOrgId: adminUserInfo.Org.Id,
  6002. PatientId: patient,
  6003. AdminUserId: adminUserInfo.AdminUser.Id,
  6004. Module: 1,
  6005. ErrLog: string(byterequest),
  6006. Status: 1,
  6007. Ctime: time.Now().Unix(),
  6008. Mtime: 0,
  6009. Source: "手机端医嘱推送",
  6010. RecordDate: item.AdviceDate,
  6011. }
  6012. service.CreateDoctorAdviceLog(adviceLog)
  6013. }
  6014. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  6015. redis := service.RedisClient()
  6016. //清空key 值
  6017. redis.Set(key, "", time.Second)
  6018. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  6019. redis.Set(keyOne, "", time.Second)
  6020. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6021. defer redis.Close()
  6022. redis.Set(keyThree, "", time.Second)
  6023. if err != nil {
  6024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  6025. return
  6026. }
  6027. c.ServeSuccessJSON(map[string]interface{}{
  6028. "msg": "ok",
  6029. "advices": list,
  6030. })
  6031. } else {
  6032. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  6033. for _, item := range advices {
  6034. byterequest, _ := json.Marshal(item)
  6035. adviceLog := models.XtDoctorAdviceLog{
  6036. UserOrgId: adminUserInfo.Org.Id,
  6037. PatientId: patient,
  6038. AdminUserId: adminUserInfo.AdminUser.Id,
  6039. Module: 1,
  6040. ErrLog: string(byterequest),
  6041. Status: 1,
  6042. Ctime: time.Now().Unix(),
  6043. Mtime: 0,
  6044. Source: "手机端医嘱推送",
  6045. RecordDate: item.AdviceDate,
  6046. }
  6047. service.CreateDoctorAdviceLog(adviceLog)
  6048. }
  6049. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  6050. redis := service.RedisClient()
  6051. //清空key 值
  6052. redis.Set(key, "", time.Second)
  6053. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  6054. redis.Set(keyOne, "", time.Second)
  6055. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6056. defer redis.Close()
  6057. redis.Set(keyThree, "", time.Second)
  6058. if err != nil {
  6059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  6060. return
  6061. }
  6062. c.ServeSuccessJSON(map[string]interface{}{
  6063. "msg": "ok",
  6064. "advices": list,
  6065. })
  6066. }
  6067. } else {
  6068. c.ServeSuccessJSON(map[string]interface{}{
  6069. "msg": "ok",
  6070. })
  6071. }
  6072. return
  6073. }
  6074. func (c *DialysisAPIController) UploadDryWeight() {
  6075. patient_id, _ := c.GetInt64("id")
  6076. dry_weight, _ := c.GetFloat("dry_weight")
  6077. doctor_id, _ := c.GetInt64("doctor_id")
  6078. remark := c.GetString("remark")
  6079. adminUserInfo := c.GetMobileAdminUserInfo()
  6080. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  6081. if err == gorm.ErrRecordNotFound {
  6082. dryWeight := &models.SgjPatientDryweight{
  6083. PatientId: patient_id,
  6084. DryWeight: dry_weight,
  6085. Remakes: remark,
  6086. Ctime: time.Now().Unix(),
  6087. Mtime: time.Now().Unix(),
  6088. Creator: doctor_id,
  6089. Status: 1,
  6090. UserOrgId: adminUserInfo.Org.Id,
  6091. AdjustedValue: "/",
  6092. UserId: adminUserInfo.AdminUser.Id,
  6093. }
  6094. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6095. redis := service.RedisClient()
  6096. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  6097. redis.Set(keyOne, "", time.Second)
  6098. loc, _ := time.LoadLocation("Local")
  6099. nowTime := time.Now()
  6100. nowDay := nowTime.Format("2006-01-02")
  6101. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6102. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6103. redis.Set(key, "", time.Second)
  6104. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6105. redis.Set(keyTwo, "", time.Second)
  6106. redis.Close()
  6107. if createErr == nil {
  6108. c.ServeSuccessJSON(map[string]interface{}{
  6109. "msg": "提交成功",
  6110. "weight": dryWeight,
  6111. })
  6112. }
  6113. } else {
  6114. dryWeight := &models.SgjPatientDryweight{
  6115. PatientId: patient_id,
  6116. DryWeight: dry_weight,
  6117. Remakes: remark,
  6118. Ctime: time.Now().Unix(),
  6119. Mtime: time.Now().Unix(),
  6120. Creator: doctor_id,
  6121. Status: 1,
  6122. UserOrgId: adminUserInfo.Org.Id,
  6123. AdjustedValue: "/",
  6124. UserId: adminUserInfo.AdminUser.Id,
  6125. }
  6126. var value float64
  6127. value = dry_weight - weightAdjust.DryWeight
  6128. if value < 0 {
  6129. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  6130. } else if value == 0 {
  6131. dryWeight.AdjustedValue = "/"
  6132. } else if value > 0 {
  6133. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  6134. }
  6135. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6136. //康桥
  6137. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  6138. timeNowStr := time.Now().Format("2006-01-02")
  6139. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6140. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6141. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6142. if beforAssesment.ID > 0 {
  6143. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  6144. var dewater_amount float64
  6145. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  6146. if adminUserInfo.Org.Id != 10702 {
  6147. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  6148. }
  6149. if adminUserInfo.Org.Id == 10702 {
  6150. service.UpdatePatientDialysisPrscriptionOne(dialysisPrescription.ID, dewater_amount)
  6151. }
  6152. //获取key,清空redis
  6153. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  6154. redis := service.RedisClient()
  6155. //清空key 值
  6156. redis.Set(key, "", time.Second)
  6157. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6158. //清空key 值
  6159. redis.Set(keyOne, "", time.Second)
  6160. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  6161. //清空key 值
  6162. redis.Set(keyTwo, "", time.Second)
  6163. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  6164. redis.Set(keySix, "", time.Second)
  6165. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  6166. redis.Set(keySeven, "", time.Second)
  6167. }
  6168. }
  6169. redis := service.RedisClient()
  6170. loc, _ := time.LoadLocation("Local")
  6171. nowTime := time.Now()
  6172. nowDay := nowTime.Format("2006-01-02")
  6173. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6174. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  6175. redis.Set(keyOne, "", time.Second)
  6176. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6177. redis.Set(key, "", time.Second)
  6178. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6179. redis.Set(keyTwo, "", time.Second)
  6180. redis.Close()
  6181. if createErr == nil {
  6182. c.ServeSuccessJSON(map[string]interface{}{
  6183. "msg": "提交成功",
  6184. "weight": dryWeight,
  6185. })
  6186. }
  6187. }
  6188. }
  6189. func (c *DialysisAPIController) GetSolution() {
  6190. patient_id, _ := c.GetInt64("patient_id")
  6191. mode_id, _ := c.GetInt64("mode_id")
  6192. adminUserInfo := c.GetMobileAdminUserInfo()
  6193. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6194. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6195. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  6196. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  6197. if err != nil {
  6198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6199. return
  6200. }
  6201. c.ServeSuccessJSON(map[string]interface{}{
  6202. "solution": solution,
  6203. "prescription": prescription,
  6204. "system_prescription": system_prescription,
  6205. "dialysisPrescription": dialysisPrescription,
  6206. })
  6207. }
  6208. func (c *DialysisAPIController) GetSchedule() {
  6209. schedual_type, _ := c.GetInt64("schedual_type")
  6210. adminUserInfo := c.GetMobileAdminUserInfo()
  6211. scheduleTime, _ := c.GetInt64("record_date")
  6212. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  6213. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  6214. c.ServeSuccessJSON(map[string]interface{}{
  6215. "number": deviceNumber,
  6216. "list": list,
  6217. })
  6218. }
  6219. func (c *DialysisAPIController) GetPatientId() {
  6220. id, _ := c.GetInt64("id")
  6221. //orgid := c.GetMobileAdminUserInfo().Org.Id
  6222. patientId, _ := service.GetPatientId(id)
  6223. //获取该患者的所有传染病
  6224. list, _ := service.GetPatientInfectious(id)
  6225. c.ServeSuccessJSON(map[string]interface{}{
  6226. "patient": patientId,
  6227. "infectioulist": list,
  6228. })
  6229. }
  6230. func (this *DialysisAPIController) GetDialysisSchedule() {
  6231. schedualDate := this.GetString("date")
  6232. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6233. if parseDateErr != nil {
  6234. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6235. return
  6236. }
  6237. adminInfo := this.GetMobileAdminUserInfo()
  6238. orgID := adminInfo.Org.Id
  6239. redis := service.RedisClient()
  6240. defer redis.Close()
  6241. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  6242. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  6243. if len(scheduals) > 0 {
  6244. //缓存数据
  6245. scheduals_json, err := json.Marshal(scheduals)
  6246. if err == nil {
  6247. redis.Set(key, scheduals_json, time.Second*30)
  6248. }
  6249. }
  6250. this.ServeSuccessJSON(map[string]interface{}{
  6251. "scheduals": scheduals,
  6252. })
  6253. }
  6254. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  6255. change_type, _ := this.GetInt64("type", 0)
  6256. record_date := this.GetString("record_time")
  6257. patient_id, _ := this.GetInt64("patient_id", 0)
  6258. timeLayout := "2006-01-02"
  6259. loc, _ := time.LoadLocation("Local")
  6260. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6261. record_time := theAdviceRecordTime.Unix()
  6262. adminUserInfo := this.GetMobileAdminUserInfo()
  6263. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  6264. if err == nil {
  6265. if len(advices) == 0 {
  6266. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6267. return
  6268. } else {
  6269. this.ServeSuccessJSON(map[string]interface{}{
  6270. "advices": advices,
  6271. "schedule": sch,
  6272. })
  6273. return
  6274. }
  6275. } else {
  6276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6277. return
  6278. }
  6279. }
  6280. func (c *DialysisAPIController) CreateConsumables() {
  6281. record_date := c.GetString("record_time")
  6282. patient_id, _ := c.GetInt64("patient_id", 0)
  6283. active, _ := c.GetInt64("active")
  6284. adminUser := c.GetMobileAdminUserInfo()
  6285. timeLayout := "2006-01-02"
  6286. loc, _ := time.LoadLocation("Local")
  6287. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6288. record_time := theRecordTime.Unix()
  6289. // 查询信息规挡的设置天数
  6290. orgid := c.GetMobileAdminUserInfo().Org.Id
  6291. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  6292. if infor.ID > 0 {
  6293. var cha_time int64
  6294. timeNowStr := time.Now().Format("2006-01-02")
  6295. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6296. //今日的日期减去设置的日期
  6297. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6298. if cha_time >= record_time {
  6299. //查询审核是否允许
  6300. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  6301. //申请状态不允许的情况 拒绝修改
  6302. if infor.ApplicationStatus != 1 {
  6303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6304. return
  6305. }
  6306. }
  6307. }
  6308. dataBody := make(map[string]interface{}, 0)
  6309. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6310. if err != nil {
  6311. utils.ErrorLog(err.Error())
  6312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6313. return
  6314. }
  6315. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6316. var beforePrepares []*models.DialysisBeforePrepareGoods
  6317. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6318. var dialysisBefor []*models.DialysisBeforePrepare
  6319. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6320. goods, _ := dataBody["goods"].([]interface{})
  6321. if len(goods) > 0 {
  6322. for _, item := range goods {
  6323. items := item.(map[string]interface{})
  6324. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6325. utils.ErrorLog("good_id")
  6326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6327. return
  6328. }
  6329. good_id := int64(items["good_id"].(float64))
  6330. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6331. utils.ErrorLog("good_type_id")
  6332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6333. return
  6334. }
  6335. good_type_id := int64(items["good_type_id"].(float64))
  6336. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6337. utils.ErrorLog("count")
  6338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6339. return
  6340. }
  6341. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6342. commdity_code := items["commdity_code"].(string)
  6343. fmt.Println("commdity", commdity_code)
  6344. prepareGoods := &models.DialysisBeforePrepareGoods{
  6345. GoodTypeId: good_type_id,
  6346. GoodId: good_id,
  6347. Count: count,
  6348. StorehouseId: houseConfig.StorehouseOutInfo,
  6349. }
  6350. beforePrepares = append(beforePrepares, prepareGoods)
  6351. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6352. GoodTypeId: good_type_id,
  6353. GoodId: good_id,
  6354. Count: count,
  6355. StorehouseId: houseConfig.StorehouseOutInfo,
  6356. }
  6357. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6358. prepare := &models.DialysisBeforePrepare{
  6359. GoodTypeId: good_type_id,
  6360. GoodId: good_id,
  6361. Count: count,
  6362. PatientId: patient_id,
  6363. RecordDate: record_time,
  6364. UserOrgId: adminUser.Org.Id,
  6365. Status: 1,
  6366. Ctime: time.Now().Unix(),
  6367. Creater: adminUser.AdminUser.Id,
  6368. CommdityCode: commdity_code,
  6369. StorehouseId: houseConfig.StorehouseOutInfo,
  6370. }
  6371. dialysisBefor = append(dialysisBefor, prepare)
  6372. }
  6373. }
  6374. //查询是否有库存
  6375. for _, item := range dialysisBefor {
  6376. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6377. if err == gorm.ErrRecordNotFound {
  6378. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6379. c.ServeSuccessJSON(map[string]interface{}{
  6380. "message": "1",
  6381. "good_name": goodObj.GoodName,
  6382. "specification_name": goodObj.SpecificationName,
  6383. })
  6384. return
  6385. }
  6386. if err != nil {
  6387. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6388. c.ServeSuccessJSON(map[string]interface{}{
  6389. "message": "1",
  6390. "good_name": goodObj.GoodName,
  6391. "specification_name": goodObj.SpecificationName,
  6392. })
  6393. return
  6394. }
  6395. }
  6396. fmt.Println("active-----------------------", active)
  6397. fmt.Println("len(goods)-----------------------", len(goods))
  6398. //新增
  6399. if active == 1 && len(goods) > 0 {
  6400. for _, item := range dialysisBefor {
  6401. dialyPrepareOne := models.DialysisBeforePrepare{
  6402. GoodTypeId: item.GoodTypeId,
  6403. GoodId: item.GoodId,
  6404. PatientId: item.PatientId,
  6405. RecordDate: item.RecordDate,
  6406. UserOrgId: item.UserOrgId,
  6407. Count: item.Count,
  6408. Ctime: time.Now().Unix(),
  6409. Creater: item.Creater,
  6410. CommdityCode: item.CommdityCode,
  6411. Status: 1,
  6412. StorehouseId: houseConfig.StorehouseOutInfo,
  6413. }
  6414. //先清除再插入
  6415. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6416. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6417. //查询默认仓库
  6418. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6419. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6420. var total_count int64
  6421. for _, it := range stockList {
  6422. total_count += it.StockCount
  6423. }
  6424. //基础库插入数据
  6425. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6426. //更新库存
  6427. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6428. var flush_count int64
  6429. for _, it := range goodList {
  6430. flush_count += it.StockCount
  6431. }
  6432. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6433. }
  6434. if err == nil {
  6435. c.ServeSuccessJSON(map[string]interface{}{
  6436. "msg": "保存成功",
  6437. "message": "2",
  6438. })
  6439. return
  6440. } else {
  6441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6442. return
  6443. }
  6444. }
  6445. if len(beforePrepares) > 0 && active == 2 {
  6446. for _, item := range beforePrepares {
  6447. //1.查看该患者该耗材型号最后一次出库数量
  6448. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6449. //判断当前出库数量和最后一次出库数量的大小
  6450. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6451. if item.Count <= goodInfo.Count {
  6452. //退库
  6453. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6454. //查询今日出库数据
  6455. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6456. for _, it := range list {
  6457. prepare := models.DialysisBeforePrepare{
  6458. UserOrgId: it.OrgId,
  6459. PatientId: patient_id,
  6460. RecordDate: it.RecordTime,
  6461. GoodId: it.GoodId,
  6462. GoodTypeId: it.GoodTypeId,
  6463. Count: it.Count,
  6464. Ctime: time.Now().Unix(),
  6465. Creater: adminUser.AdminUser.Id,
  6466. Status: 1,
  6467. StorehouseId: houseConfig.StorehouseOutInfo,
  6468. }
  6469. //删除准备表数据
  6470. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6471. service.CreateDialysisBeforePrepareOne(&prepare)
  6472. }
  6473. }
  6474. var last_total int64
  6475. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6476. if item.Count >= goodInfo.Count {
  6477. //查询当前批次当前耗材最后一条出库数据
  6478. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6479. //计算当前出库和最后一次出库数据相差数据
  6480. last_total = item.Count - lastOutInfo.Count
  6481. //查询该批次剩余库存
  6482. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6483. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6484. if lastInfo.StockCount >= last_total {
  6485. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6486. //查询今日出库数据
  6487. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6488. for _, it := range list {
  6489. prepare := models.DialysisBeforePrepare{
  6490. UserOrgId: it.OrgId,
  6491. PatientId: patient_id,
  6492. RecordDate: it.RecordTime,
  6493. GoodId: it.GoodId,
  6494. GoodTypeId: it.GoodTypeId,
  6495. Count: it.Count,
  6496. Ctime: time.Now().Unix(),
  6497. Creater: adminUser.AdminUser.Id,
  6498. Status: 1,
  6499. StorehouseId: houseConfig.StorehouseOutInfo,
  6500. }
  6501. //删除准备表数据
  6502. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6503. service.CreateDialysisBeforePrepareOne(&prepare)
  6504. //查询默认仓库
  6505. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6506. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6507. var total_count int64
  6508. for _, it := range stockList {
  6509. total_count += it.StockCount
  6510. }
  6511. //基础库插入数据
  6512. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6513. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6514. var flush_count int64
  6515. for _, it := range goodList {
  6516. flush_count += it.StockCount
  6517. }
  6518. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6519. }
  6520. }
  6521. //如果库存不够,则出库到下一个批次
  6522. if lastInfo.StockCount < last_total {
  6523. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6524. //查询今日出库数据
  6525. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6526. for _, it := range list {
  6527. prepare := models.DialysisBeforePrepare{
  6528. UserOrgId: it.OrgId,
  6529. PatientId: patient_id,
  6530. RecordDate: it.RecordTime,
  6531. GoodId: it.GoodId,
  6532. GoodTypeId: it.GoodTypeId,
  6533. Count: it.Count,
  6534. Ctime: time.Now().Unix(),
  6535. Creater: adminUser.AdminUser.Id,
  6536. Status: 1,
  6537. StorehouseId: houseConfig.StorehouseOutInfo,
  6538. }
  6539. //删除准备表数据
  6540. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6541. service.CreateDialysisBeforePrepareOne(&prepare)
  6542. //查询默认仓库
  6543. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6544. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6545. var total_count int64
  6546. for _, it := range stockList {
  6547. total_count += it.StockCount
  6548. }
  6549. //基础库插入数据
  6550. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6551. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6552. var flush_count int64
  6553. for _, it := range goodList {
  6554. flush_count += it.StockCount
  6555. }
  6556. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6557. }
  6558. if err != nil {
  6559. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6560. c.ServeSuccessJSON(map[string]interface{}{
  6561. "message": "1",
  6562. "good_name": goodObj.GoodName,
  6563. "specification_name": goodObj.SpecificationName,
  6564. })
  6565. return
  6566. }
  6567. }
  6568. }
  6569. if err != nil {
  6570. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6571. c.ServeSuccessJSON(map[string]interface{}{
  6572. "message": "1",
  6573. "good_name": goodObj.GoodName,
  6574. "specification_name": goodObj.SpecificationName,
  6575. })
  6576. return
  6577. }
  6578. }
  6579. }
  6580. }
  6581. var errs error
  6582. if errs == nil {
  6583. c.ServeSuccessJSON(map[string]interface{}{
  6584. "msg": "提交成功",
  6585. "message": "2",
  6586. "good_name": "",
  6587. "specification_name": "",
  6588. })
  6589. return
  6590. } else {
  6591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6592. return
  6593. }
  6594. }
  6595. func (c *DialysisAPIController) CreateStockOutInfo() {
  6596. patient_id, _ := c.GetInt64("patient_id", 0)
  6597. record_date := c.GetString("record_time")
  6598. if patient_id <= 0 {
  6599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6600. return
  6601. }
  6602. adminInfo := c.GetMobileAdminUserInfo()
  6603. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6604. timeLayout := "2006-01-02"
  6605. loc, _ := time.LoadLocation("Local")
  6606. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6607. record_time := theRecordTime.Unix()
  6608. // 查询信息规挡的设置天数
  6609. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6610. if infor.ID > 0 && infor.WeekDay > 0 {
  6611. var cha_time int64
  6612. timeNowStr := time.Now().Format("2006-01-02")
  6613. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6614. //今日的日期减去设置的日期
  6615. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6616. if cha_time >= record_time {
  6617. //查询审核是否允许
  6618. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6619. //申请状态不允许的情况 拒绝修改
  6620. if infor.ApplicationStatus != 1 {
  6621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6622. return
  6623. }
  6624. }
  6625. }
  6626. //创建步骤表
  6627. finish := models.XtDialysisFinish{
  6628. IsFinish: 1,
  6629. UserOrgId: adminInfo.Org.Id,
  6630. Status: 1,
  6631. Ctime: time.Now().Unix(),
  6632. Mtime: 0,
  6633. Module: 11,
  6634. RecordDate: record_time,
  6635. Sourse: 1,
  6636. PatientId: patient_id,
  6637. }
  6638. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6639. if dialysisFinish.ID == 0 {
  6640. service.CreateDialysisFinish(finish)
  6641. }
  6642. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6643. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6644. //去重
  6645. consumables = RemoveRepeatedGood(consumables)
  6646. if adminInfo.Org.Id == 9919 {
  6647. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6648. //查询是否有库存
  6649. for _, item := range consumables {
  6650. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6651. if item.Count > warehouse.Count {
  6652. goodErrcode := models.XtGoodErrcode{
  6653. UserOrgId: item.UserOrgId,
  6654. Errcode: "自动出库库存不足",
  6655. GoodId: item.GoodId,
  6656. Status: 1,
  6657. Ctime: time.Now().Unix(),
  6658. Mtime: 0,
  6659. Count: 0,
  6660. StockCount: 0,
  6661. Creater: creator,
  6662. BatchNumberId: warehouse.ID,
  6663. WarehouseOutId: 0,
  6664. }
  6665. service.CreateGoodErrcode(goodErrcode)
  6666. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6667. c.ServeSuccessJSON(map[string]interface{}{
  6668. "message": "1",
  6669. "good_name": goodObj.GoodName,
  6670. "specification_name": goodObj.SpecificationName,
  6671. })
  6672. return
  6673. }
  6674. }
  6675. //查询是否有出库单
  6676. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6677. if err == gorm.ErrRecordNotFound {
  6678. //没有记录,则创建出库单
  6679. timeStr := time.Now().Format("2006-01-02")
  6680. timeArr := strings.Split(timeStr, "-")
  6681. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6682. total = total + 1
  6683. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6684. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6685. number = number + total
  6686. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6687. creater := adminInfo.AdminUser.Id
  6688. warehouseOut := models.WarehouseOut{
  6689. WarehouseOutOrderNumber: warehousing_out_order,
  6690. OperationTime: time.Now().Unix(),
  6691. OrgId: adminInfo.Org.Id,
  6692. Creater: creater,
  6693. Ctime: time.Now().Unix(),
  6694. Status: 1,
  6695. WarehouseOutTime: record_time,
  6696. Dealer: 0,
  6697. Manufacturer: 0,
  6698. Type: 1,
  6699. IsSys: 1,
  6700. StorehouseId: houseConfig.StorehouseOutInfo,
  6701. IsCheck: 1,
  6702. }
  6703. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6704. if err != nil {
  6705. goodErrcode := models.XtGoodErrcode{
  6706. UserOrgId: adminInfo.Org.Id,
  6707. Errcode: "创建出库单失败",
  6708. GoodId: 0,
  6709. Status: 1,
  6710. Ctime: time.Now().Unix(),
  6711. Mtime: 0,
  6712. Count: 0,
  6713. StockCount: 0,
  6714. Creater: creator,
  6715. BatchNumberId: 0,
  6716. WarehouseOutId: 0,
  6717. }
  6718. service.CreateGoodErrcode(goodErrcode)
  6719. utils.TraceLog("创建出库单失败 err = %v", err)
  6720. } else {
  6721. for _, item := range consumables {
  6722. //出库
  6723. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6724. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6725. if err == nil {
  6726. goodErrcode := models.XtGoodErrcode{
  6727. UserOrgId: adminInfo.Org.Id,
  6728. Errcode: "自动出库接口报错",
  6729. GoodId: 0,
  6730. Status: 1,
  6731. Ctime: time.Now().Unix(),
  6732. Mtime: 0,
  6733. Count: 0,
  6734. StockCount: 0,
  6735. Creater: creator,
  6736. BatchNumberId: 0,
  6737. WarehouseOutId: 0,
  6738. }
  6739. service.CreateGoodErrcode(goodErrcode)
  6740. utils.TraceLog("创建出库单失败 err = %v", err)
  6741. }
  6742. //查询
  6743. //出库数量相加
  6744. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6745. if errs != nil {
  6746. goodErrcode := models.XtGoodErrcode{
  6747. UserOrgId: item.UserOrgId,
  6748. Errcode: "创建剩余库存字段报错",
  6749. GoodId: item.GoodId,
  6750. Status: 1,
  6751. Ctime: time.Now().Unix(),
  6752. Mtime: 0,
  6753. Count: 0,
  6754. StockCount: 0,
  6755. Creater: creater,
  6756. BatchNumberId: 0,
  6757. WarehouseOutId: 0,
  6758. }
  6759. service.CreateGoodErrcode(goodErrcode)
  6760. }
  6761. }
  6762. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6763. if len(list) == 0 {
  6764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6765. return
  6766. }
  6767. for _, item := range list {
  6768. prepare := models.DialysisBeforePrepare{
  6769. UserOrgId: adminInfo.Org.Id,
  6770. PatientId: patient_id,
  6771. RecordDate: record_time,
  6772. GoodId: item.GoodId,
  6773. GoodTypeId: item.GoodTypeId,
  6774. Count: item.Count,
  6775. Creater: adminInfo.AdminUser.Id,
  6776. Status: 1,
  6777. Ctime: time.Now().Unix(),
  6778. StorehouseId: houseConfig.StorehouseOutInfo,
  6779. }
  6780. //清空准备表数据
  6781. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6782. if err != nil {
  6783. goodErrcode := models.XtGoodErrcode{
  6784. UserOrgId: item.OrgId,
  6785. Errcode: "自动出库清空准备表数据报错",
  6786. GoodId: item.GoodId,
  6787. Status: 1,
  6788. Ctime: time.Now().Unix(),
  6789. Mtime: 0,
  6790. Count: 0,
  6791. StockCount: 0,
  6792. Creater: creater,
  6793. BatchNumberId: 0,
  6794. WarehouseOutId: 0,
  6795. }
  6796. service.CreateGoodErrcode(goodErrcode)
  6797. }
  6798. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6799. if errs != nil {
  6800. goodErrcode := models.XtGoodErrcode{
  6801. UserOrgId: item.OrgId,
  6802. Errcode: "自动出库创建准备表数据报错",
  6803. GoodId: item.GoodId,
  6804. Status: 1,
  6805. Ctime: time.Now().Unix(),
  6806. Mtime: 0,
  6807. Count: 0,
  6808. StockCount: 0,
  6809. Creater: creater,
  6810. BatchNumberId: 0,
  6811. WarehouseOutId: 0,
  6812. }
  6813. service.CreateGoodErrcode(goodErrcode)
  6814. }
  6815. //查询默认仓库
  6816. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6817. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6818. var total_count int64
  6819. for _, it := range stockList {
  6820. total_count += it.StockCount
  6821. }
  6822. //基础库插入数据
  6823. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6824. if errcodes != nil {
  6825. goodErrcode := models.XtGoodErrcode{
  6826. UserOrgId: item.OrgId,
  6827. Errcode: "自动出库基础库插入数据",
  6828. GoodId: item.GoodId,
  6829. Status: 1,
  6830. Ctime: time.Now().Unix(),
  6831. Mtime: 0,
  6832. Count: 0,
  6833. StockCount: 0,
  6834. Creater: creater,
  6835. BatchNumberId: 0,
  6836. WarehouseOutId: 0,
  6837. }
  6838. service.CreateGoodErrcode(goodErrcode)
  6839. }
  6840. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6841. var flush_count int64
  6842. for _, it := range goodList {
  6843. flush_count += it.StockCount
  6844. }
  6845. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6846. if errsss != nil {
  6847. goodErrcode := models.XtGoodErrcode{
  6848. UserOrgId: item.OrgId,
  6849. Errcode: "自动出库剩余库存更新数据",
  6850. GoodId: item.GoodId,
  6851. Status: 1,
  6852. Ctime: time.Now().Unix(),
  6853. Mtime: 0,
  6854. Count: 0,
  6855. StockCount: 0,
  6856. Creater: creater,
  6857. BatchNumberId: 0,
  6858. WarehouseOutId: 0,
  6859. }
  6860. service.CreateGoodErrcode(goodErrcode)
  6861. }
  6862. }
  6863. }
  6864. //
  6865. } else if err == nil {
  6866. for _, item := range consumables {
  6867. //出库
  6868. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6869. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  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. }
  6886. //出库数量相加
  6887. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6888. if errss != nil {
  6889. goodErrcode := models.XtGoodErrcode{
  6890. UserOrgId: item.UserOrgId,
  6891. Errcode: "创建剩余库存字段报错",
  6892. GoodId: item.GoodId,
  6893. Status: 1,
  6894. Ctime: time.Now().Unix(),
  6895. Mtime: time.Now().Unix(),
  6896. Count: 0,
  6897. StockCount: 0,
  6898. Creater: item.Creater,
  6899. BatchNumberId: 0,
  6900. WarehouseOutId: 0,
  6901. }
  6902. service.CreateGoodErrcode(goodErrcode)
  6903. }
  6904. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6905. if len(list) == 0 {
  6906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6907. return
  6908. }
  6909. for _, item := range list {
  6910. prepare := models.DialysisBeforePrepare{
  6911. UserOrgId: adminInfo.Org.Id,
  6912. PatientId: patient_id,
  6913. RecordDate: record_time,
  6914. GoodId: item.GoodId,
  6915. GoodTypeId: item.GoodTypeId,
  6916. Count: item.Count,
  6917. Creater: adminInfo.AdminUser.Id,
  6918. Status: 1,
  6919. Ctime: time.Now().Unix(),
  6920. StorehouseId: houseConfig.StorehouseOutInfo,
  6921. }
  6922. //清空准备表数据
  6923. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6924. if errs != nil {
  6925. goodErrcode := models.XtGoodErrcode{
  6926. UserOrgId: adminInfo.Org.Id,
  6927. Errcode: "自动出库清空准备表数据报错",
  6928. GoodId: 0,
  6929. Status: 1,
  6930. Ctime: time.Now().Unix(),
  6931. Mtime: 0,
  6932. Count: 0,
  6933. StockCount: 0,
  6934. Creater: creator,
  6935. BatchNumberId: 0,
  6936. WarehouseOutId: 0,
  6937. }
  6938. service.CreateGoodErrcode(goodErrcode)
  6939. }
  6940. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6941. if errcodes != nil {
  6942. goodErrcode := models.XtGoodErrcode{
  6943. UserOrgId: adminInfo.Org.Id,
  6944. Errcode: "自动出库创建准备表数据报错",
  6945. GoodId: 0,
  6946. Status: 1,
  6947. Ctime: time.Now().Unix(),
  6948. Mtime: 0,
  6949. Count: 0,
  6950. StockCount: 0,
  6951. Creater: creator,
  6952. BatchNumberId: 0,
  6953. WarehouseOutId: 0,
  6954. }
  6955. service.CreateGoodErrcode(goodErrcode)
  6956. }
  6957. //查询默认仓库
  6958. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6959. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6960. var total_count int64
  6961. for _, it := range stockList {
  6962. total_count += it.StockCount
  6963. }
  6964. //基础库插入数据
  6965. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6966. if errcodes != nil {
  6967. goodErrcode := models.XtGoodErrcode{
  6968. UserOrgId: adminInfo.Org.Id,
  6969. Errcode: "自动出库基础库插入数据报错",
  6970. GoodId: 0,
  6971. Status: 1,
  6972. Ctime: time.Now().Unix(),
  6973. Mtime: 0,
  6974. Count: 0,
  6975. StockCount: 0,
  6976. Creater: creator,
  6977. BatchNumberId: 0,
  6978. WarehouseOutId: 0,
  6979. }
  6980. service.CreateGoodErrcode(goodErrcode)
  6981. }
  6982. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6983. var flush_count int64
  6984. for _, it := range goodList {
  6985. flush_count += it.StockCount
  6986. }
  6987. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6988. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6989. if errss != nil {
  6990. goodErrcode := models.XtGoodErrcode{
  6991. UserOrgId: item.OrgId,
  6992. Errcode: "自动出库剩余库存更新数据",
  6993. GoodId: item.GoodId,
  6994. Status: 1,
  6995. Ctime: time.Now().Unix(),
  6996. Mtime: 0,
  6997. Count: 0,
  6998. StockCount: 0,
  6999. Creater: creater,
  7000. BatchNumberId: 0,
  7001. WarehouseOutId: 0,
  7002. }
  7003. service.CreateGoodErrcode(goodErrcode)
  7004. }
  7005. }
  7006. }
  7007. }
  7008. c.ServeSuccessJSON(map[string]interface{}{
  7009. "msg": "提交成功",
  7010. "message": "2",
  7011. "good_name": "",
  7012. "specification_name": "",
  7013. })
  7014. return
  7015. }
  7016. if record.IsOpen == 1 {
  7017. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7018. //查询是否有库存
  7019. for _, item := range consumables {
  7020. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  7021. if item.Count > warehouse.Count {
  7022. goodErrcode := models.XtGoodErrcode{
  7023. UserOrgId: item.UserOrgId,
  7024. Errcode: "自动出库库存不足",
  7025. GoodId: item.GoodId,
  7026. Status: 1,
  7027. Ctime: time.Now().Unix(),
  7028. Mtime: 0,
  7029. Count: 0,
  7030. StockCount: 0,
  7031. Creater: creator,
  7032. BatchNumberId: warehouse.ID,
  7033. WarehouseOutId: 0,
  7034. }
  7035. service.CreateGoodErrcode(goodErrcode)
  7036. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7037. c.ServeSuccessJSON(map[string]interface{}{
  7038. "message": "1",
  7039. "good_name": goodObj.GoodName,
  7040. "specification_name": goodObj.SpecificationName,
  7041. })
  7042. return
  7043. }
  7044. }
  7045. //查询是否有出库单
  7046. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7047. if err == gorm.ErrRecordNotFound {
  7048. //没有记录,则创建出库单
  7049. timeStr := time.Now().Format("2006-01-02")
  7050. timeArr := strings.Split(timeStr, "-")
  7051. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7052. total = total + 1
  7053. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7054. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7055. number = number + total
  7056. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7057. creater := adminInfo.AdminUser.Id
  7058. warehouseOut := models.WarehouseOut{
  7059. WarehouseOutOrderNumber: warehousing_out_order,
  7060. OperationTime: time.Now().Unix(),
  7061. OrgId: adminInfo.Org.Id,
  7062. Creater: creater,
  7063. Ctime: time.Now().Unix(),
  7064. Status: 1,
  7065. WarehouseOutTime: record_time,
  7066. Dealer: 0,
  7067. Manufacturer: 0,
  7068. Type: 1,
  7069. IsSys: 1,
  7070. StorehouseId: houseConfig.StorehouseOutInfo,
  7071. IsCheck: 1,
  7072. }
  7073. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  7074. if err != nil {
  7075. goodErrcode := models.XtGoodErrcode{
  7076. UserOrgId: adminInfo.Org.Id,
  7077. Errcode: "创建出库单失败",
  7078. GoodId: 0,
  7079. Status: 1,
  7080. Ctime: time.Now().Unix(),
  7081. Mtime: 0,
  7082. Count: 0,
  7083. StockCount: 0,
  7084. Creater: creator,
  7085. BatchNumberId: 0,
  7086. WarehouseOutId: 0,
  7087. }
  7088. service.CreateGoodErrcode(goodErrcode)
  7089. utils.TraceLog("创建出库单失败 err = %v", err)
  7090. } else {
  7091. for _, item := range consumables {
  7092. //出库
  7093. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  7094. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  7095. if err == nil {
  7096. goodErrcode := models.XtGoodErrcode{
  7097. UserOrgId: adminInfo.Org.Id,
  7098. Errcode: "自动出库接口报错",
  7099. GoodId: 0,
  7100. Status: 1,
  7101. Ctime: time.Now().Unix(),
  7102. Mtime: 0,
  7103. Count: 0,
  7104. StockCount: 0,
  7105. Creater: creator,
  7106. BatchNumberId: 0,
  7107. WarehouseOutId: 0,
  7108. }
  7109. service.CreateGoodErrcode(goodErrcode)
  7110. utils.TraceLog("创建出库单失败 err = %v", err)
  7111. }
  7112. //查询
  7113. //出库数量相加
  7114. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7115. if errs != nil {
  7116. goodErrcode := models.XtGoodErrcode{
  7117. UserOrgId: item.UserOrgId,
  7118. Errcode: "创建剩余库存字段报错",
  7119. GoodId: item.GoodId,
  7120. Status: 1,
  7121. Ctime: time.Now().Unix(),
  7122. Mtime: 0,
  7123. Count: 0,
  7124. StockCount: 0,
  7125. Creater: creater,
  7126. BatchNumberId: 0,
  7127. WarehouseOutId: 0,
  7128. }
  7129. service.CreateGoodErrcode(goodErrcode)
  7130. }
  7131. }
  7132. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7133. if len(list) == 0 {
  7134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7135. return
  7136. }
  7137. for _, item := range list {
  7138. prepare := models.DialysisBeforePrepare{
  7139. UserOrgId: adminInfo.Org.Id,
  7140. PatientId: patient_id,
  7141. RecordDate: record_time,
  7142. GoodId: item.GoodId,
  7143. GoodTypeId: item.GoodTypeId,
  7144. Count: item.Count,
  7145. Creater: adminInfo.AdminUser.Id,
  7146. Status: 1,
  7147. Ctime: time.Now().Unix(),
  7148. StorehouseId: houseConfig.StorehouseOutInfo,
  7149. }
  7150. //清空准备表数据
  7151. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7152. if err != nil {
  7153. goodErrcode := models.XtGoodErrcode{
  7154. UserOrgId: item.OrgId,
  7155. Errcode: "自动出库清空准备表数据报错",
  7156. GoodId: item.GoodId,
  7157. Status: 1,
  7158. Ctime: time.Now().Unix(),
  7159. Mtime: 0,
  7160. Count: 0,
  7161. StockCount: 0,
  7162. Creater: creater,
  7163. BatchNumberId: 0,
  7164. WarehouseOutId: 0,
  7165. }
  7166. service.CreateGoodErrcode(goodErrcode)
  7167. }
  7168. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  7169. if errs != nil {
  7170. goodErrcode := models.XtGoodErrcode{
  7171. UserOrgId: item.OrgId,
  7172. Errcode: "自动出库创建准备表数据报错",
  7173. GoodId: item.GoodId,
  7174. Status: 1,
  7175. Ctime: time.Now().Unix(),
  7176. Mtime: 0,
  7177. Count: 0,
  7178. StockCount: 0,
  7179. Creater: creater,
  7180. BatchNumberId: 0,
  7181. WarehouseOutId: 0,
  7182. }
  7183. service.CreateGoodErrcode(goodErrcode)
  7184. }
  7185. //查询默认仓库
  7186. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7187. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7188. var total_count int64
  7189. for _, it := range stockList {
  7190. total_count += it.StockCount
  7191. }
  7192. //基础库插入数据
  7193. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7194. if errcodes != nil {
  7195. goodErrcode := models.XtGoodErrcode{
  7196. UserOrgId: item.OrgId,
  7197. Errcode: "自动出库基础库插入数据",
  7198. GoodId: item.GoodId,
  7199. Status: 1,
  7200. Ctime: time.Now().Unix(),
  7201. Mtime: 0,
  7202. Count: 0,
  7203. StockCount: 0,
  7204. Creater: creater,
  7205. BatchNumberId: 0,
  7206. WarehouseOutId: 0,
  7207. }
  7208. service.CreateGoodErrcode(goodErrcode)
  7209. }
  7210. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7211. var flush_count int64
  7212. for _, it := range goodList {
  7213. flush_count += it.StockCount
  7214. }
  7215. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7216. if errsss != nil {
  7217. goodErrcode := models.XtGoodErrcode{
  7218. UserOrgId: item.OrgId,
  7219. Errcode: "自动出库剩余库存更新数据",
  7220. GoodId: item.GoodId,
  7221. Status: 1,
  7222. Ctime: time.Now().Unix(),
  7223. Mtime: 0,
  7224. Count: 0,
  7225. StockCount: 0,
  7226. Creater: creater,
  7227. BatchNumberId: 0,
  7228. WarehouseOutId: 0,
  7229. }
  7230. service.CreateGoodErrcode(goodErrcode)
  7231. }
  7232. }
  7233. }
  7234. //
  7235. } else if err == nil {
  7236. for _, item := range consumables {
  7237. //出库
  7238. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  7239. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  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. }
  7256. //出库数量相加
  7257. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7258. if errss != nil {
  7259. goodErrcode := models.XtGoodErrcode{
  7260. UserOrgId: item.UserOrgId,
  7261. Errcode: "创建剩余库存字段报错",
  7262. GoodId: item.GoodId,
  7263. Status: 1,
  7264. Ctime: time.Now().Unix(),
  7265. Mtime: time.Now().Unix(),
  7266. Count: 0,
  7267. StockCount: 0,
  7268. Creater: item.Creater,
  7269. BatchNumberId: 0,
  7270. WarehouseOutId: 0,
  7271. }
  7272. service.CreateGoodErrcode(goodErrcode)
  7273. }
  7274. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7275. if len(list) == 0 {
  7276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7277. return
  7278. }
  7279. for _, item := range list {
  7280. prepare := models.DialysisBeforePrepare{
  7281. UserOrgId: adminInfo.Org.Id,
  7282. PatientId: patient_id,
  7283. RecordDate: record_time,
  7284. GoodId: item.GoodId,
  7285. GoodTypeId: item.GoodTypeId,
  7286. Count: item.Count,
  7287. Creater: adminInfo.AdminUser.Id,
  7288. Status: 1,
  7289. Ctime: time.Now().Unix(),
  7290. StorehouseId: houseConfig.StorehouseOutInfo,
  7291. }
  7292. //清空准备表数据
  7293. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7294. if errs != nil {
  7295. goodErrcode := models.XtGoodErrcode{
  7296. UserOrgId: adminInfo.Org.Id,
  7297. Errcode: "自动出库清空准备表数据报错",
  7298. GoodId: 0,
  7299. Status: 1,
  7300. Ctime: time.Now().Unix(),
  7301. Mtime: 0,
  7302. Count: 0,
  7303. StockCount: 0,
  7304. Creater: creator,
  7305. BatchNumberId: 0,
  7306. WarehouseOutId: 0,
  7307. }
  7308. service.CreateGoodErrcode(goodErrcode)
  7309. }
  7310. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  7311. if errcodes != nil {
  7312. goodErrcode := models.XtGoodErrcode{
  7313. UserOrgId: adminInfo.Org.Id,
  7314. Errcode: "自动出库创建准备表数据报错",
  7315. GoodId: 0,
  7316. Status: 1,
  7317. Ctime: time.Now().Unix(),
  7318. Mtime: 0,
  7319. Count: 0,
  7320. StockCount: 0,
  7321. Creater: creator,
  7322. BatchNumberId: 0,
  7323. WarehouseOutId: 0,
  7324. }
  7325. service.CreateGoodErrcode(goodErrcode)
  7326. }
  7327. //查询默认仓库
  7328. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7329. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7330. var total_count int64
  7331. for _, it := range stockList {
  7332. total_count += it.StockCount
  7333. }
  7334. //基础库插入数据
  7335. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7336. if errcodes != nil {
  7337. goodErrcode := models.XtGoodErrcode{
  7338. UserOrgId: adminInfo.Org.Id,
  7339. Errcode: "自动出库基础库插入数据报错",
  7340. GoodId: 0,
  7341. Status: 1,
  7342. Ctime: time.Now().Unix(),
  7343. Mtime: 0,
  7344. Count: 0,
  7345. StockCount: 0,
  7346. Creater: creator,
  7347. BatchNumberId: 0,
  7348. WarehouseOutId: 0,
  7349. }
  7350. service.CreateGoodErrcode(goodErrcode)
  7351. }
  7352. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7353. var flush_count int64
  7354. for _, it := range goodList {
  7355. flush_count += it.StockCount
  7356. }
  7357. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7358. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7359. if errss != nil {
  7360. goodErrcode := models.XtGoodErrcode{
  7361. UserOrgId: item.OrgId,
  7362. Errcode: "自动出库剩余库存更新数据",
  7363. GoodId: item.GoodId,
  7364. Status: 1,
  7365. Ctime: time.Now().Unix(),
  7366. Mtime: 0,
  7367. Count: 0,
  7368. StockCount: 0,
  7369. Creater: creater,
  7370. BatchNumberId: 0,
  7371. WarehouseOutId: 0,
  7372. }
  7373. service.CreateGoodErrcode(goodErrcode)
  7374. }
  7375. }
  7376. }
  7377. }
  7378. c.ServeSuccessJSON(map[string]interface{}{
  7379. "msg": "提交成功",
  7380. "message": "2",
  7381. "good_name": "",
  7382. "specification_name": "",
  7383. })
  7384. return
  7385. } else {
  7386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  7387. return
  7388. }
  7389. }
  7390. func (c *DialysisAPIController) EditConsumables() {
  7391. patient_id, _ := c.GetInt64("patient_id", 0)
  7392. record_date := c.GetString("record_time")
  7393. if patient_id <= 0 {
  7394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7395. return
  7396. }
  7397. adminInfo := c.GetMobileAdminUserInfo()
  7398. timeLayout := "2006-01-02"
  7399. loc, _ := time.LoadLocation("Local")
  7400. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7401. record_time := theRecordTime.Unix()
  7402. // 查询信息规挡的设置天数
  7403. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7404. if infor.ID > 0 && infor.WeekDay > 0 {
  7405. var cha_time int64
  7406. timeNowStr := time.Now().Format("2006-01-02")
  7407. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7408. //今日的日期减去设置的日期
  7409. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7410. if cha_time >= record_time {
  7411. //查询审核是否允许
  7412. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7413. //申请状态不允许的情况 拒绝修改
  7414. if infor.ApplicationStatus != 1 {
  7415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7416. return
  7417. }
  7418. }
  7419. }
  7420. dataBody := make(map[string]interface{}, 0)
  7421. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7422. if err != nil {
  7423. utils.ErrorLog(err.Error())
  7424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7425. return
  7426. }
  7427. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7428. var beforePrepares []*models.DialysisBeforePrepareGoods
  7429. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7430. var cancelbefor []*models.DialysisBeforePrepareGoods
  7431. var outbefor []*models.DialysisBeforePrepareGoods
  7432. //判断是否开启自动出库
  7433. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7434. if record.IsOpen == 1 {
  7435. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7436. goods, _ := dataBody["goods"].([]interface{})
  7437. if len(goods) > 0 {
  7438. for _, item := range goods {
  7439. items := item.(map[string]interface{})
  7440. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7441. utils.ErrorLog("good_id")
  7442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7443. return
  7444. }
  7445. good_id := int64(items["good_id"].(float64))
  7446. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7447. utils.ErrorLog("good_type_id")
  7448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7449. return
  7450. }
  7451. good_type_id := int64(items["good_type_id"].(float64))
  7452. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7453. utils.ErrorLog("count")
  7454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7455. return
  7456. }
  7457. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7458. commdity_code := items["commdity_code"].(string)
  7459. fmt.Println(commdity_code)
  7460. prepareGoods := &models.DialysisBeforePrepareGoods{
  7461. GoodTypeId: good_type_id,
  7462. GoodId: good_id,
  7463. Count: count,
  7464. StorehouseId: houseConfig.StorehouseOutInfo,
  7465. }
  7466. beforePrepares = append(beforePrepares, prepareGoods)
  7467. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7468. GoodTypeId: good_type_id,
  7469. GoodId: good_id,
  7470. Count: count,
  7471. StorehouseId: houseConfig.StorehouseOutInfo,
  7472. }
  7473. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7474. }
  7475. for _, item := range beforePrepares {
  7476. //1.查看该患者该耗材型号最后一次出库数量
  7477. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7478. //判断当前出库数量和最后一次出库数量的大小
  7479. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7480. if item.Count < goodInfo.Count {
  7481. cancelbefor = append(cancelbefor, item)
  7482. }
  7483. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7484. if item.Count > goodInfo.Count {
  7485. outbefor = append(outbefor, item)
  7486. }
  7487. //处理编辑耗材新增不了的问题
  7488. if goodInfo.Count == item.Count {
  7489. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7490. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7491. }
  7492. }
  7493. if len(cancelbefor) > 0 {
  7494. //退库
  7495. for _, item := range cancelbefor {
  7496. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7497. creater := adminInfo.AdminUser.Id
  7498. //查询该患者当天已经出库的耗材信息
  7499. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7500. var delete_count int64 = 0
  7501. delete_count = warehouseOutInfos.Count - item.Count
  7502. //增加库存数量
  7503. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7504. //减少实际出库库存数量
  7505. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7506. // 删除出库完成后,要增加对应批次的库存数量
  7507. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7508. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7509. //更新剩余库存
  7510. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7511. var flush_count int64
  7512. for _, it := range goodListOne {
  7513. flush_count += it.StockCount
  7514. }
  7515. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7516. //查询剩余库存
  7517. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7518. var sum_count int64
  7519. for _, item := range goodList {
  7520. sum_count += item.StockCount
  7521. }
  7522. // 在出库记录表里记录退库详情
  7523. warehouseOutInfo := &models.WarehouseOutInfo{
  7524. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7525. WarehouseOutId: warehouseOut.ID,
  7526. Status: 1,
  7527. Ctime: time.Now().Unix(),
  7528. OrgId: adminInfo.Org.Id,
  7529. Type: 1,
  7530. IsSys: 1,
  7531. SysRecordTime: record_time,
  7532. GoodTypeId: item.GoodTypeId,
  7533. GoodId: item.GoodId,
  7534. PatientId: patient_id,
  7535. ConsumableType: 2,
  7536. StorehouseId: houseConfig.StorehouseOutInfo,
  7537. IsCheck: 1,
  7538. OverCount: sum_count,
  7539. }
  7540. warehouseOutInfo.Count = item.Count
  7541. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7542. warehouseOutInfo.Price = stockInInfo.Price
  7543. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7544. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7545. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7546. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7547. warehouseOutInfo.Number = warehouseOutInfos.Number
  7548. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7549. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7550. //查找当天是否存在出库记录
  7551. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7552. if errcod == gorm.ErrRecordNotFound {
  7553. service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  7554. //插入详情明细表
  7555. stockFlow := models.VmStockFlow{
  7556. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7557. WarehouseOutId: warehouseOut.ID,
  7558. GoodId: item.GoodId,
  7559. Number: warehouseOutInfos.Number,
  7560. ProductDate: stockInInfo.ProductDate,
  7561. ExpireDate: stockInInfo.ExpiryDate,
  7562. Count: item.Count,
  7563. Price: stockInInfo.Price,
  7564. Status: 1,
  7565. Ctime: record_time,
  7566. UserOrgId: adminInfo.Org.Id,
  7567. Manufacturer: stockInInfo.Manufacturer,
  7568. Dealer: stockInInfo.Dealer,
  7569. LicenseNumber: stockInInfo.LicenseNumber,
  7570. IsEdit: 2,
  7571. Creator: creater,
  7572. SystemTime: record_time,
  7573. ConsumableType: 3,
  7574. WarehousingDetailId: 0,
  7575. IsSys: 1,
  7576. UpdateCreator: creater,
  7577. PatientId: patient_id,
  7578. StorehouseId: houseConfig.StorehouseOutInfo,
  7579. }
  7580. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7581. if errflow == gorm.ErrRecordNotFound {
  7582. //创建流水表
  7583. err := service.CreateStockFlowOne(stockFlow)
  7584. fmt.Println("err", err)
  7585. } else if errflow == nil {
  7586. //插入详情明细表
  7587. stockFlow := models.VmStockFlow{
  7588. ID: exsit.ID,
  7589. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7590. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7591. WarehouseOutId: warehouseOut.ID,
  7592. GoodId: item.GoodId,
  7593. Number: warehouseOutInfos.Number,
  7594. ProductDate: stockInInfo.ProductDate,
  7595. ExpireDate: stockInInfo.ExpiryDate,
  7596. Count: exsit.Count - delete_count,
  7597. Price: stockInInfo.Price,
  7598. Status: 1,
  7599. Ctime: record_time,
  7600. UserOrgId: adminInfo.Org.Id,
  7601. Manufacturer: stockInInfo.Manufacturer,
  7602. Dealer: stockInInfo.Dealer,
  7603. LicenseNumber: stockInInfo.LicenseNumber,
  7604. IsEdit: 2,
  7605. Creator: creater,
  7606. SystemTime: record_time,
  7607. ConsumableType: 3,
  7608. WarehousingDetailId: 0,
  7609. IsSys: 1,
  7610. UpdateCreator: creater,
  7611. PatientId: patient_id,
  7612. StorehouseId: houseConfig.StorehouseOutInfo,
  7613. }
  7614. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7615. }
  7616. } else if errcod == nil {
  7617. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7618. //查询剩余库存
  7619. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7620. var sum_count int64
  7621. for _, item := range goodList {
  7622. sum_count += item.StockCount
  7623. }
  7624. //创建退库单,生成退库数据
  7625. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7626. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7627. operation_time := time.Now().Unix()
  7628. creater := adminInfo.AdminUser.Id
  7629. //创建退库单
  7630. timeStr := time.Now().Format("2006-01-02")
  7631. timeArr := strings.Split(timeStr, "-")
  7632. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7633. total = total + 1
  7634. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7635. cancelStock := models.CancelStock{
  7636. OrderNumber: orderNumber,
  7637. OperaTime: operation_time,
  7638. OrgId: adminInfo.Org.Id,
  7639. Creater: creater,
  7640. Ctime: time.Now().Unix(),
  7641. Status: 1,
  7642. ReturnTime: record_time,
  7643. Type: 1,
  7644. StorehouseId: houseConfig.StorehouseOutInfo,
  7645. IsCheck: 1,
  7646. }
  7647. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7648. if msgerrkonde == gorm.ErrRecordNotFound {
  7649. service.AddSigleCancelStock(&cancelStock)
  7650. }
  7651. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7652. //查询是否有出库
  7653. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7654. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7655. deaerler, _ := service.GetDealerById(info.Dealer)
  7656. if info.ID > 0 {
  7657. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7658. cancelStockInfo := models.CancelStockInfo{
  7659. GoodId: item.GoodId,
  7660. CancelStockId: cancel.ID,
  7661. GoodTypeId: good.GoodTypeId,
  7662. Count: delete_count,
  7663. Price: info.Price,
  7664. Total: 0,
  7665. ProductDate: info.ProductDate,
  7666. ExpiryDate: info.ExpiryDate,
  7667. Ctime: time.Now().Unix(),
  7668. Status: 1,
  7669. OrgId: adminInfo.Org.Id,
  7670. OrderNumber: cancel.OrderNumber,
  7671. Type: 0,
  7672. Dealer: deaerler.DealerName,
  7673. Manufacturer: manufacturer.ManufacturerName,
  7674. Number: info.Number,
  7675. RegisterAccount: "",
  7676. Remark: "",
  7677. WarehouseInfoId: info.WarehouseInfotId,
  7678. PatientId: info.PatientId,
  7679. RecordDate: info.SysRecordTime,
  7680. StorehouseId: houseConfig.StorehouseOutInfo,
  7681. IsCheck: 1,
  7682. }
  7683. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7684. //退库数量增加
  7685. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7686. //查询剩余库存
  7687. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7688. var over_count int64
  7689. for _, it := range goodList {
  7690. over_count += it.StockCount
  7691. }
  7692. flow := models.VmStockFlow{
  7693. WarehousingId: info.WarehouseInfotId,
  7694. GoodId: item.GoodId,
  7695. Number: info.Number,
  7696. LicenseNumber: info.LicenseNumber,
  7697. Count: delete_count,
  7698. UserOrgId: adminInfo.Org.Id,
  7699. PatientId: patient_id,
  7700. SystemTime: info.SysRecordTime,
  7701. ConsumableType: 7,
  7702. IsSys: 0,
  7703. WarehousingOrder: "",
  7704. WarehouseOutId: info.WarehouseOutId,
  7705. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7706. IsEdit: 0,
  7707. CancelStockId: cancel.ID,
  7708. CancelOrderNumber: cancel.OrderNumber,
  7709. Manufacturer: manufacturer.ID,
  7710. Dealer: 0,
  7711. Creator: adminInfo.AdminUser.Id,
  7712. UpdateCreator: 0,
  7713. Status: 1,
  7714. Ctime: record_time,
  7715. Mtime: 0,
  7716. Price: info.Price,
  7717. WarehousingDetailId: info.WarehouseInfotId,
  7718. WarehouseOutDetailId: info.ID,
  7719. CancelOutDetailId: cancelInfo.ID,
  7720. ProductDate: info.ProductDate,
  7721. ExpireDate: info.ExpiryDate,
  7722. StorehouseId: houseConfig.StorehouseOutInfo,
  7723. OverCount: over_count,
  7724. }
  7725. service.CreateStockFlowOne(flow)
  7726. }
  7727. }
  7728. //更改自动出库的表格
  7729. details := models.BloodAutomaticReduceDetail{
  7730. WarehouseOutId: warehouseOutInfo.ID,
  7731. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7732. PatientId: patient_id,
  7733. Ctime: time.Now().Unix(),
  7734. Mtime: time.Now().Unix(),
  7735. Status: 1,
  7736. RecordTime: record_time,
  7737. OrgId: adminInfo.Org.Id,
  7738. GoodId: item.GoodId,
  7739. GoodTypeId: item.GoodTypeId,
  7740. Count: item.Count,
  7741. StorehouseId: houseConfig.StorehouseOutInfo,
  7742. }
  7743. //查询当天耗材是否已经存在数据
  7744. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7745. if errcode == gorm.ErrRecordNotFound {
  7746. service.CreateAutoReduceRecord(&details)
  7747. } else if errcode == nil {
  7748. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7749. service.CreateAutoReduceRecord(&details)
  7750. }
  7751. //查询默认仓库
  7752. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7753. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7754. var total_count int64
  7755. for _, it := range stockList {
  7756. total_count += it.StockCount
  7757. }
  7758. //基础库插入数据
  7759. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7760. }
  7761. }
  7762. if len(outbefor) > 0 {
  7763. //出库
  7764. for _, item := range outbefor {
  7765. var last_total int64
  7766. //1.查看该患者该耗材型号最后一次出库数量
  7767. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7768. //计算当前出库和最后一次出库数据相差数据
  7769. last_total = item.Count - goodInfoOne.Count
  7770. //查询该耗材的总库存
  7771. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7772. // 如果库存差大于剩余库存则提示库存不足
  7773. if last_total > wareinfo.StockCount {
  7774. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7775. c.ServeSuccessJSON(map[string]interface{}{
  7776. "message": "1",
  7777. "good_name": goodObj.GoodName,
  7778. "specification_name": goodObj.SpecificationName,
  7779. })
  7780. return
  7781. } else {
  7782. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7783. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7784. if err == gorm.ErrRecordNotFound {
  7785. //没有记录,则创建出库单
  7786. timeStr := time.Now().Format("2006-01-02")
  7787. timeArr := strings.Split(timeStr, "-")
  7788. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7789. total = total + 1
  7790. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7791. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7792. number = number + total
  7793. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7794. warehouseOut := models.WarehouseOut{
  7795. WarehouseOutOrderNumber: warehousing_out_order,
  7796. OperationTime: time.Now().Unix(),
  7797. OrgId: adminInfo.Org.Id,
  7798. Creater: adminInfo.AdminUser.Id,
  7799. Ctime: time.Now().Unix(),
  7800. Status: 1,
  7801. WarehouseOutTime: record_time,
  7802. Dealer: 0,
  7803. Manufacturer: 0,
  7804. Type: 1,
  7805. IsSys: 1,
  7806. StorehouseId: houseConfig.StorehouseOutInfo,
  7807. IsCheck: 1,
  7808. }
  7809. service.AddSigleWarehouseOutOne(&warehouseOut)
  7810. }
  7811. //出库
  7812. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7813. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7814. //1.查看该患者该耗材型号最后一次出库数量
  7815. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7816. prepare := models.DialysisBeforePrepare{
  7817. UserOrgId: adminInfo.Org.Id,
  7818. PatientId: patient_id,
  7819. RecordDate: record_time,
  7820. GoodId: item.GoodId,
  7821. GoodTypeId: item.GoodTypeId,
  7822. Count: item.Count - goodInfoTwo.Count,
  7823. Ctime: time.Now().Unix(),
  7824. Mtime: 0,
  7825. Creater: adminInfo.AdminUser.Id,
  7826. Modifier: adminInfo.AdminUser.Id,
  7827. Status: 1,
  7828. CommdityCode: "",
  7829. NewCount: 0,
  7830. ProjectId: 0,
  7831. StorehouseId: houseConfig.StorehouseOutInfo,
  7832. }
  7833. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7834. //增加出库数量
  7835. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7836. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7837. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7838. var total_count int64
  7839. for _, it := range stockList {
  7840. total_count += it.StockCount
  7841. }
  7842. //基础库插入数据
  7843. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7844. //剩余库存
  7845. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7846. var flush_count int64
  7847. for _, it := range goodList {
  7848. flush_count += it.StockCount
  7849. }
  7850. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7851. }
  7852. }
  7853. }
  7854. //查询今日出库数据
  7855. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7856. for _, it := range list {
  7857. prepare := models.DialysisBeforePrepare{
  7858. UserOrgId: it.OrgId,
  7859. PatientId: patient_id,
  7860. RecordDate: it.RecordTime,
  7861. GoodId: it.GoodId,
  7862. GoodTypeId: it.GoodTypeId,
  7863. Count: it.Count,
  7864. Ctime: time.Now().Unix(),
  7865. Creater: adminInfo.AdminUser.Id,
  7866. Status: 1,
  7867. StorehouseId: houseConfig.StorehouseOutInfo,
  7868. ProjectId: it.ProjectId,
  7869. }
  7870. //删除准备表数据
  7871. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7872. service.CreateDialysisBeforePrepareOne(&prepare)
  7873. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7874. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7875. var total_count int64
  7876. for _, it := range stockList {
  7877. total_count += it.StockCount
  7878. }
  7879. //基础库插入数据
  7880. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7881. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7882. var flush_count int64
  7883. for _, it := range goodList {
  7884. flush_count += it.StockCount
  7885. }
  7886. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7887. }
  7888. }
  7889. }
  7890. //更新自动出库的地方
  7891. var errs error
  7892. if errs == nil {
  7893. c.ServeSuccessJSON(map[string]interface{}{
  7894. "msg": "修改成功",
  7895. "message": "2",
  7896. "good_name": "",
  7897. "specification_name": "",
  7898. })
  7899. return
  7900. } else {
  7901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7902. return
  7903. }
  7904. }
  7905. }
  7906. func (c *DialysisAPIController) GetDialysisGoods() {
  7907. schedualDate := c.GetString("schedule_date")
  7908. schedule_type, _ := c.GetInt64("schedule_type")
  7909. partition_id, _ := c.GetInt64("partition_id")
  7910. page, _ := c.GetInt("page")
  7911. patient_id, _ := c.GetInt64("patient_id")
  7912. schedualEndDate := int64(0)
  7913. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7914. if parseDateErr != nil && len(schedualDate) != 0 {
  7915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7916. return
  7917. }
  7918. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7919. if parseDateErr != nil && len(schedualDate) != 0 {
  7920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7921. return
  7922. }
  7923. schedualEndDate = endDate.Unix()
  7924. adminUser := c.GetMobileAdminUserInfo()
  7925. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7926. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7927. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7928. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7929. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7930. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7931. //获取当天该病人的透析处方
  7932. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7933. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7934. if err == gorm.ErrRecordNotFound {
  7935. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7936. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7937. if patient_id != 0 {
  7938. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7939. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7940. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7941. //获取患者总的出库数据
  7942. item.LastAutomaticReduceDetail = goodUser
  7943. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7944. item.Project = project
  7945. for _, it := range item.AutomaticReduceDetail {
  7946. var total int64
  7947. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7948. for _, its := range auto {
  7949. total += its.Count
  7950. }
  7951. it.Count = total
  7952. }
  7953. }
  7954. }
  7955. c.ServeSuccessJSON(map[string]interface{}{
  7956. "dialysis_goods": dialysisGoods,
  7957. "good_type": goodTypes,
  7958. "total": total,
  7959. "prescribe": prescribe,
  7960. "good_info": good_info,
  7961. "warehouseOutList": warehouseOutList,
  7962. "config": config,
  7963. "outConfig": outConfig,
  7964. "settleConfig": settleConfig,
  7965. })
  7966. return
  7967. } else if err == nil {
  7968. //获取当天排班的每个患者的库存使用情况
  7969. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7970. //获取患者总的出库数据
  7971. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7972. if patient_id != 0 {
  7973. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7974. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7975. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7976. item.Project = project
  7977. item.LastAutomaticReduceDetail = goodUser
  7978. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7979. for _, it := range item.AutomaticReduceDetail {
  7980. var total int64
  7981. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7982. for _, its := range auto {
  7983. total += its.Count
  7984. }
  7985. it.Count = total
  7986. }
  7987. }
  7988. }
  7989. if err == nil {
  7990. c.ServeSuccessJSON(map[string]interface{}{
  7991. "dialysis_goods": dialysisGoods,
  7992. "good_type": goodTypes,
  7993. "total": total,
  7994. "prescribe": prescribe,
  7995. "good_info": good_info,
  7996. "project": project,
  7997. "warehouseOutList": warehouseOutList,
  7998. "config": config,
  7999. "outConfig": outConfig,
  8000. "settleConfig": settleConfig,
  8001. })
  8002. return
  8003. } else {
  8004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8005. return
  8006. }
  8007. } else if err != nil {
  8008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8009. return
  8010. }
  8011. }
  8012. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  8013. start_time := c.GetString("start_time")
  8014. end_time := c.GetString("end_time")
  8015. timeLayout := "2006-01-02"
  8016. loc, _ := time.LoadLocation("Local")
  8017. var theStartTime int64
  8018. if len(start_time) > 0 {
  8019. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8020. if err != nil {
  8021. utils.ErrorLog(err.Error())
  8022. }
  8023. theStartTime = theTime.Unix()
  8024. }
  8025. var theEndtTime int64
  8026. if len(end_time) > 0 {
  8027. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8028. if err != nil {
  8029. utils.ErrorLog(err.Error())
  8030. }
  8031. theEndtTime = theTime.Unix()
  8032. }
  8033. adminUser := c.GetMobileAdminUserInfo()
  8034. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  8035. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  8036. if err == nil {
  8037. c.ServeSuccessJSON(map[string]interface{}{
  8038. "stock_out": outInfo,
  8039. "stockCount": stockCount,
  8040. })
  8041. return
  8042. } else {
  8043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8044. return
  8045. }
  8046. }
  8047. func (c *DialysisAPIController) GetStockInGoodInfo() {
  8048. patient_id, _ := c.GetInt64("patient_id", 0)
  8049. record_time := c.GetString("record_time")
  8050. adminUser := c.GetMobileAdminUserInfo()
  8051. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  8052. if parseDateErr != nil && len(record_time) != 0 {
  8053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8054. return
  8055. }
  8056. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  8057. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  8058. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  8059. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  8060. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  8061. //获取今日患者的透析处方参数
  8062. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  8063. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  8064. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  8065. c.ServeSuccessJSON(map[string]interface{}{
  8066. "good_type": goodTypes,
  8067. "good_user": goodUser,
  8068. "good_info": good_info,
  8069. "last_good_user": lastGoodUserDetial,
  8070. "project": project,
  8071. "prescription": prescribe,
  8072. "outInfo": outInfo,
  8073. "configs": configs,
  8074. })
  8075. return
  8076. }
  8077. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  8078. patient_id, _ := c.GetInt64("patient_id", 0)
  8079. record_date := c.GetString("record_time")
  8080. timeLayout := "2006-01-02"
  8081. loc, _ := time.LoadLocation("Local")
  8082. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8083. record_time := theRecordTime.Unix()
  8084. adminInfo := c.GetMobileAdminUserInfo()
  8085. dataBody := make(map[string]interface{}, 0)
  8086. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8087. if err != nil {
  8088. utils.ErrorLog(err.Error())
  8089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8090. return
  8091. }
  8092. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8093. var beforePrepares []*models.DialysisBeforePrepareGoods
  8094. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  8095. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  8096. goods, _ := dataBody["goods"].([]interface{})
  8097. if len(goods) > 0 {
  8098. for _, item := range goods {
  8099. items := item.(map[string]interface{})
  8100. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  8101. utils.ErrorLog("good_id")
  8102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8103. return
  8104. }
  8105. good_id := int64(items["good_id"].(float64))
  8106. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  8107. utils.ErrorLog("good_type_id")
  8108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8109. return
  8110. }
  8111. good_type_id := int64(items["good_type_id"].(float64))
  8112. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  8113. utils.ErrorLog("count")
  8114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8115. return
  8116. }
  8117. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  8118. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  8119. utils.ErrorLog("project_id")
  8120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8121. return
  8122. }
  8123. project_id := int64(items["project_id"].(float64))
  8124. new_count := int64(items["new_count"].(float64))
  8125. old_count := int64(items["old_count"].(float64))
  8126. prepare := &models.DialysisBeforePrepareGoods{
  8127. GoodId: good_id,
  8128. GoodTypeId: good_type_id,
  8129. Count: count,
  8130. ProjectId: project_id,
  8131. StorehouseId: houseConfig.StorehouseOutInfo,
  8132. NewCount: new_count,
  8133. OldCount: old_count,
  8134. }
  8135. beforePrepares = append(beforePrepares, prepare)
  8136. newPrepare := &models.NewDialysisBeforePrepareGoods{
  8137. GoodId: good_id,
  8138. GoodTypeId: good_type_id,
  8139. Count: count,
  8140. ProjectId: project_id,
  8141. StorehouseId: houseConfig.StorehouseOutInfo,
  8142. NewCount: new_count,
  8143. OldCount: old_count,
  8144. }
  8145. newBeforePrepares = append(newBeforePrepares, newPrepare)
  8146. }
  8147. }
  8148. }
  8149. //查询是否有库存
  8150. for _, item := range beforePrepares {
  8151. if item.NewCount > 0 {
  8152. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8153. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  8154. if item.Count > warehouse.Count {
  8155. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  8156. c.ServeSuccessJSON(map[string]interface{}{
  8157. "message": "1",
  8158. "good_name": goodObj.GoodName,
  8159. "specification_name": goodObj.SpecificationName,
  8160. })
  8161. return
  8162. }
  8163. }
  8164. }
  8165. // 查询信息规挡的设置天数
  8166. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  8167. if infor.ID > 0 && infor.WeekDay > 0 {
  8168. var cha_time int64
  8169. timeNowStr := time.Now().Format("2006-01-02")
  8170. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  8171. //今日的日期减去设置的日期
  8172. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  8173. if cha_time >= record_time {
  8174. //查询审核是否允许
  8175. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  8176. //申请状态不允许的情况 拒绝修改
  8177. if infor.ApplicationStatus != 1 {
  8178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  8179. return
  8180. }
  8181. }
  8182. }
  8183. //出库逻辑
  8184. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  8185. if err != nil {
  8186. utils.ErrorLog(err.Error())
  8187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8188. return
  8189. }
  8190. finish := models.XtDialysisFinish{
  8191. IsFinish: 1,
  8192. UserOrgId: adminInfo.Org.Id,
  8193. Status: 1,
  8194. Ctime: time.Now().Unix(),
  8195. Mtime: 0,
  8196. Module: 11,
  8197. RecordDate: record_time,
  8198. Sourse: 1,
  8199. PatientId: patient_id,
  8200. }
  8201. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  8202. if dialysisFinish.ID == 0 {
  8203. service.CreateDialysisFinish(finish)
  8204. }
  8205. //查询当天出库的数据
  8206. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  8207. for _, item := range list {
  8208. prepare := models.DialysisBeforePrepare{
  8209. UserOrgId: item.OrgId,
  8210. PatientId: item.PatientId,
  8211. RecordDate: item.RecordTime,
  8212. GoodId: item.GoodId,
  8213. GoodTypeId: item.GoodTypeId,
  8214. Count: item.Count,
  8215. Creater: adminInfo.AdminUser.Id,
  8216. Status: 1,
  8217. Ctime: time.Now().Unix(),
  8218. ProjectId: item.ProjectId,
  8219. StorehouseId: houseConfig.StorehouseOutInfo,
  8220. }
  8221. //清空准备表的数据
  8222. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  8223. //插入准备表数据
  8224. service.CreateDialysisBeforePrepareOne(&prepare)
  8225. //查询默认仓库
  8226. //查询默认仓库
  8227. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8228. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  8229. var total_count int64
  8230. for _, it := range stockList {
  8231. total_count += it.StockCount
  8232. }
  8233. //基础库插入数据
  8234. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  8235. ////更新剩余库存
  8236. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  8237. var flush_count int64
  8238. for _, it := range goodList {
  8239. flush_count += it.StockCount
  8240. }
  8241. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  8242. if errs != nil {
  8243. goodErrcode := models.XtGoodErrcode{
  8244. UserOrgId: item.OrgId,
  8245. Errcode: "手动出库更新剩余出库失败",
  8246. GoodId: item.GoodId,
  8247. Status: 1,
  8248. Ctime: time.Now().Unix(),
  8249. Mtime: 0,
  8250. Count: 0,
  8251. StockCount: 0,
  8252. Creater: adminInfo.AdminUser.Id,
  8253. BatchNumberId: 0,
  8254. WarehouseOutId: 0,
  8255. }
  8256. service.CreateGoodErrcode(goodErrcode)
  8257. }
  8258. }
  8259. //更新自动出库的地方
  8260. var errs error
  8261. if errs == nil {
  8262. c.ServeSuccessJSON(map[string]interface{}{
  8263. "msg": "修改成功",
  8264. "message": "2",
  8265. "good_name": "",
  8266. "specification_name": "",
  8267. })
  8268. return
  8269. } else {
  8270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8271. return
  8272. }
  8273. }
  8274. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8275. newArr = make([]*models.DialysisBeforePrepare, 0)
  8276. for i := 0; i < len(arr); i++ {
  8277. repeat := false
  8278. for j := i + 1; j < len(arr); j++ {
  8279. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  8280. repeat = true
  8281. break
  8282. }
  8283. }
  8284. if !repeat {
  8285. newArr = append(newArr, arr[i])
  8286. }
  8287. }
  8288. return
  8289. }
  8290. func (c *DialysisAPIController) GetAllDrug() {
  8291. patient_id, _ := c.GetInt64("patient_id", 0)
  8292. adminInfo := c.GetMobileAdminUserInfo()
  8293. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  8294. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  8295. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  8296. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  8297. c.ServeSuccessJSON(map[string]interface{}{
  8298. "base_drug_config": drugStockConfig,
  8299. "private_drug_config": privateDrugConfig,
  8300. "base_drug_list": drugList,
  8301. "private_drug_list": privateDrugList,
  8302. })
  8303. }
  8304. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8305. newArr = make([]*models.DialysisBeforePrepare, 0)
  8306. for i := 0; i < len(arr); i++ {
  8307. repeat := false
  8308. for j := i + 1; j < len(arr); j++ {
  8309. if arr[i].GoodId == arr[j].GoodId {
  8310. repeat = true
  8311. break
  8312. }
  8313. }
  8314. if !repeat {
  8315. newArr = append(newArr, arr[i])
  8316. }
  8317. }
  8318. return
  8319. }
  8320. func (c *DialysisAPIController) GetDepartment() {
  8321. adminInfo := c.GetMobileAdminUserInfo()
  8322. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  8323. if err == nil {
  8324. c.ServeSuccessJSON(map[string]interface{}{
  8325. "departments": departments,
  8326. })
  8327. } else {
  8328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8329. return
  8330. }
  8331. }
  8332. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  8333. types, _ := c.GetInt("type", 0)
  8334. start_time := c.GetString("start_time")
  8335. end_time := c.GetString("end_time")
  8336. orgId := c.GetMobileAdminUserInfo().Org.Id
  8337. timeLayout := "2006-01-02"
  8338. loc, _ := time.LoadLocation("Local")
  8339. var startTime int64
  8340. if len(start_time) > 0 {
  8341. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8342. if err != nil {
  8343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8344. return
  8345. }
  8346. startTime = theTime.Unix()
  8347. }
  8348. var endTime int64
  8349. if len(end_time) > 0 {
  8350. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8351. if err != nil {
  8352. utils.ErrorLog(err.Error())
  8353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8354. return
  8355. }
  8356. endTime = theTime.Unix()
  8357. }
  8358. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  8359. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  8360. if err != nil {
  8361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8362. } else {
  8363. c.ServeSuccessJSON(map[string]interface{}{
  8364. "list": list,
  8365. "type": types,
  8366. "stockTotal": stockTotal,
  8367. })
  8368. }
  8369. }
  8370. func (c *DialysisAPIController) GetPrescriptionList() {
  8371. start_time := c.GetString("start_time")
  8372. end_time := c.GetString("end_time")
  8373. schedule_type, _ := c.GetInt64("schedule_type")
  8374. partion_id, _ := c.GetInt64("partion_id")
  8375. orgId := c.GetMobileAdminUserInfo().Org.Id
  8376. timeLayout := "2006-01-02"
  8377. loc, _ := time.LoadLocation("Local")
  8378. var startTime int64
  8379. if len(start_time) > 0 {
  8380. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8381. if err != nil {
  8382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8383. return
  8384. }
  8385. startTime = theTime.Unix()
  8386. }
  8387. var endTime int64
  8388. if len(end_time) > 0 {
  8389. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8390. if err != nil {
  8391. utils.ErrorLog(err.Error())
  8392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8393. return
  8394. }
  8395. endTime = theTime.Unix()
  8396. }
  8397. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  8398. fmt.Println("schedulelist22222222", schedulelist)
  8399. c.ServeSuccessJSON(map[string]interface{}{
  8400. "list": schedulelist,
  8401. })
  8402. return
  8403. }
  8404. func (c *DialysisAPIController) BatchDeleteMonitor() {
  8405. ids := c.GetString("ids")
  8406. //patient_id, _ := c.GetInt64("patient_id")
  8407. //monitoring_date, _ := c.GetInt64("monitoring_date")
  8408. idArray := strings.Split(ids, ",")
  8409. err := service.BatchDeleteMonitor(idArray)
  8410. fmt.Print("err", err)
  8411. //orgid := c.GetMobileAdminUserInfo().Org.Id
  8412. //redis := service.RedisClient()
  8413. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  8414. //redis.Set(key, "", time.Second)
  8415. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  8416. //redis.Set(keyOne, "", time.Second)
  8417. //fmt.Println("keyo呢32332322332332232332",keyOne)
  8418. //redis.Close()
  8419. c.ServeSuccessJSON(map[string]interface{}{
  8420. "msg": "批量删除成功",
  8421. })
  8422. return
  8423. }
  8424. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  8425. id, _ := c.GetInt64("id")
  8426. timeLayout := "2006-01-02"
  8427. loc, _ := time.LoadLocation("Local")
  8428. //start_time := time.Now().Format("2006-01-02")
  8429. start_time := c.GetString("start_time")
  8430. end_time := c.GetString("end_time")
  8431. var startdateunix int64
  8432. if len(start_time) > 0 {
  8433. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8434. if err != nil {
  8435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8436. return
  8437. }
  8438. startdateunix = theTime.Unix()
  8439. }
  8440. var enddateunix int64
  8441. if len(end_time) > 0 {
  8442. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8443. if err != nil {
  8444. utils.ErrorLog(err.Error())
  8445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8446. return
  8447. }
  8448. enddateunix = theTime.Unix()
  8449. }
  8450. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8451. //nowTime := time.Now()
  8452. //endTime := nowTime.AddDate(-30, 0, 0)
  8453. //endTimes := endTime.Format("2006-01-02")
  8454. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8455. org_id := c.GetMobileAdminUserInfo().Org.Id
  8456. //if org_id == 10579 {
  8457. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8458. // c.ServeSuccessJSON(map[string]interface{}{
  8459. // "list": list,
  8460. // })
  8461. // return
  8462. //} else {
  8463. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8464. // c.ServeSuccessJSON(map[string]interface{}{
  8465. // "list": list,
  8466. // })
  8467. // return
  8468. //}
  8469. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8470. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8471. c.ServeSuccessJSON(map[string]interface{}{
  8472. "list": list,
  8473. })
  8474. return
  8475. } else {
  8476. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8477. c.ServeSuccessJSON(map[string]interface{}{
  8478. "list": list,
  8479. })
  8480. }
  8481. return
  8482. }
  8483. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8484. dataBody := make(map[string]interface{}, 0)
  8485. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8486. ids := c.GetString("ids")
  8487. idArray := strings.Split(ids, ",")
  8488. origin, _ := c.GetInt64("origin")
  8489. if origin == 1 {
  8490. err = service.BatchDeleteAdvice(idArray)
  8491. fmt.Print("err", err)
  8492. c.ServeSuccessJSON(map[string]interface{}{
  8493. "msg": "批量删除成功",
  8494. })
  8495. return
  8496. }
  8497. if origin == 2 {
  8498. service.BatchDeleteHisAdvice(idArray)
  8499. }
  8500. }
  8501. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8502. good_id, _ := c.GetInt64("good_id")
  8503. count, _ := c.GetInt64("count")
  8504. record_time, _ := c.GetInt64("record_time")
  8505. patient_id, _ := c.GetInt64("patient_id")
  8506. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8507. c.ServeSuccessJSON(map[string]interface{}{
  8508. "detail": detail,
  8509. })
  8510. return
  8511. }
  8512. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8513. good_id, _ := c.GetInt64("good_id")
  8514. record_time, _ := c.GetInt64("record_time")
  8515. patient_id, _ := c.GetInt64("patient_id")
  8516. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8517. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8518. fmt.Print("err", err)
  8519. c.ServeSuccessJSON(map[string]interface{}{
  8520. "msg": "批量删除成功",
  8521. })
  8522. return
  8523. }
  8524. func (c *DialysisAPIController) BatchAdviceCheck() {
  8525. ids := c.GetString("ids")
  8526. idArray := strings.Split(ids, ",")
  8527. creator, _ := c.GetInt64("creator")
  8528. origin, _ := c.GetInt64("origin")
  8529. if origin == 1 {
  8530. err := service.BatchAdviceCheck(idArray, creator)
  8531. fmt.Println(err)
  8532. list, _ := service.GetAdviceExecutionById(idArray)
  8533. c.ServeSuccessJSON(map[string]interface{}{
  8534. "list": list,
  8535. })
  8536. return
  8537. }
  8538. if origin == 2 {
  8539. service.BatchHisAdviceCheck(idArray, creator)
  8540. list, _ := service.GetHisAdviceExecutionById(idArray)
  8541. c.ServeSuccessJSON(map[string]interface{}{
  8542. "list": list,
  8543. })
  8544. return
  8545. }
  8546. }
  8547. func (c *DialysisAPIController) BatchAdviceExecution() {
  8548. ids := c.GetString("ids")
  8549. idArray := strings.Split(ids, ",")
  8550. executionTime := c.GetString("execution_time")
  8551. creator, _ := c.GetInt64("creator")
  8552. timeLayout := "2006-01-02 15:04:05"
  8553. loc, _ := time.LoadLocation("Local")
  8554. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8555. orgin, _ := c.GetInt64("origin")
  8556. if orgin == 1 {
  8557. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8558. list, _ := service.GetAdviceExecutionById(idArray)
  8559. fmt.Println(err)
  8560. c.ServeSuccessJSON(map[string]interface{}{
  8561. "list": list,
  8562. })
  8563. return
  8564. }
  8565. if orgin == 2 {
  8566. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8567. list, _ := service.GetHisAdviceExecutionById(idArray)
  8568. fmt.Println(err)
  8569. c.ServeSuccessJSON(map[string]interface{}{
  8570. "list": list,
  8571. })
  8572. return
  8573. }
  8574. }
  8575. func (c *DialysisAPIController) UpdateStockGoods() {
  8576. good_id, _ := c.GetInt64("good_id")
  8577. record_time, _ := c.GetInt64("record_time")
  8578. patient_id, _ := c.GetInt64("patient_id")
  8579. count, _ := c.GetInt64("count")
  8580. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8581. fmt.Print("err", err)
  8582. c.ServeSuccessJSON(map[string]interface{}{
  8583. "msg": "更新成功",
  8584. })
  8585. return
  8586. }
  8587. // 当前数据比上一次出库数据少
  8588. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8589. //查询该患者当天已经出库的耗材信息
  8590. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8591. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8592. for i := len(goods_yc) - 1; i >= 0; i-- {
  8593. goods_yc_temp := goods_yc[i]
  8594. for j := len(goods) - 1; j >= 0; j-- {
  8595. goods_temp := goods[j]
  8596. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8597. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8598. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8599. if goods_yc_temp.Count == goods_temp.Count {
  8600. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8601. goods = append(goods[:j], goods[j+1:]...)
  8602. break
  8603. }
  8604. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8605. if goods_yc_temp.Count > goods_temp.Count {
  8606. temp_count := goods_yc_temp.Count - goods_temp.Count
  8607. goods_yc[i].Count = temp_count
  8608. goods = append(goods[:j], goods[j+1:]...)
  8609. break
  8610. }
  8611. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8612. if goods_yc_temp.Count < goods_temp.Count {
  8613. temp_count := goods_temp.Count - goods_yc_temp.Count
  8614. goods[j].Count = temp_count
  8615. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8616. break
  8617. }
  8618. }
  8619. }
  8620. }
  8621. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8622. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8623. //退库
  8624. if len(goods_yc) > 0 {
  8625. for _, good_yc := range goods_yc {
  8626. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8627. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8628. }
  8629. }
  8630. return nil
  8631. }
  8632. // 耗材出库删除
  8633. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8634. // 先根据相关信息查询当天该耗材的出库信息
  8635. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8636. if err != nil {
  8637. return err
  8638. }
  8639. var delete_count int64 = 0
  8640. delete_count = warehouseOutInfos.Count - count
  8641. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8642. // 在出库记录表里记录退库详情
  8643. warehouseOutInfo := &models.WarehouseOutInfo{
  8644. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8645. WarehouseOutId: warehouseOut.ID,
  8646. Status: 1,
  8647. Ctime: time.Now().Unix(),
  8648. OrgId: orgID,
  8649. Type: 1,
  8650. IsSys: 1,
  8651. SysRecordTime: record_time,
  8652. GoodTypeId: good_yc.GoodTypeId,
  8653. GoodId: good_yc.GoodId,
  8654. PatientId: good_yc.PatientId,
  8655. ConsumableType: 2,
  8656. StorehouseId: houseConfig.StorehouseOutInfo,
  8657. IsCheck: 1,
  8658. }
  8659. warehouseOutInfo.Count = count
  8660. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8661. warehouseOutInfo.Price = stockInInfo.Price
  8662. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8663. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8664. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8665. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8666. warehouseOutInfo.Number = warehouseOutInfos.Number
  8667. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8668. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8669. //查找当天是否存在出库记录
  8670. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8671. if errcod == gorm.ErrRecordNotFound {
  8672. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8673. //插入详情明细表
  8674. stockFlow := models.VmStockFlow{
  8675. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8676. WarehouseOutId: warehouseOut.ID,
  8677. GoodId: good_yc.GoodId,
  8678. Number: warehouseOutInfos.Number,
  8679. ProductDate: stockInInfo.ProductDate,
  8680. ExpireDate: stockInInfo.ExpiryDate,
  8681. Count: count,
  8682. Price: stockInInfo.Price,
  8683. Status: 1,
  8684. Ctime: time.Now().Unix(),
  8685. UserOrgId: good_yc.OrgId,
  8686. Manufacturer: stockInInfo.Manufacturer,
  8687. Dealer: stockInInfo.Dealer,
  8688. LicenseNumber: stockInInfo.LicenseNumber,
  8689. IsEdit: 2,
  8690. Creator: creater,
  8691. SystemTime: record_time,
  8692. ConsumableType: 3,
  8693. WarehousingDetailId: 0,
  8694. IsSys: 1,
  8695. UpdateCreator: creater,
  8696. PatientId: patient_id,
  8697. StorehouseId: houseConfig.StorehouseOutInfo,
  8698. }
  8699. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8700. if errflow == gorm.ErrRecordNotFound {
  8701. //创建流水表
  8702. err := service.CreateStockFlowOne(stockFlow)
  8703. fmt.Println("err", err)
  8704. } else if errflow == nil {
  8705. //插入详情明细表
  8706. stockFlow := models.VmStockFlow{
  8707. ID: exsit.ID,
  8708. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8709. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8710. WarehouseOutId: warehouseOut.ID,
  8711. GoodId: good_yc.GoodId,
  8712. Number: warehouseOutInfos.Number,
  8713. ProductDate: stockInInfo.ProductDate,
  8714. ExpireDate: stockInInfo.ExpiryDate,
  8715. Count: exsit.Count - delete_count,
  8716. Price: stockInInfo.Price,
  8717. Status: 1,
  8718. Ctime: time.Now().Unix(),
  8719. UserOrgId: good_yc.OrgId,
  8720. Manufacturer: stockInInfo.Manufacturer,
  8721. Dealer: stockInInfo.Dealer,
  8722. LicenseNumber: stockInInfo.LicenseNumber,
  8723. IsEdit: 2,
  8724. Creator: creater,
  8725. SystemTime: record_time,
  8726. ConsumableType: 3,
  8727. WarehousingDetailId: 0,
  8728. IsSys: 1,
  8729. UpdateCreator: creater,
  8730. PatientId: patient_id,
  8731. StorehouseId: houseConfig.StorehouseOutInfo,
  8732. }
  8733. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8734. }
  8735. if errOne != nil {
  8736. return errOne
  8737. }
  8738. } else if errcod == nil {
  8739. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8740. //插入详情明细表
  8741. stockFlow := models.VmStockFlow{
  8742. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8743. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8744. WarehouseOutId: warehouseOut.ID,
  8745. GoodId: good_yc.GoodId,
  8746. Number: warehouseOutInfos.Number,
  8747. ProductDate: stockInInfo.ProductDate,
  8748. ExpireDate: stockInInfo.ExpiryDate,
  8749. Count: count,
  8750. Price: stockInInfo.Price,
  8751. Status: 1,
  8752. Ctime: time.Now().Unix(),
  8753. UserOrgId: good_yc.OrgId,
  8754. Manufacturer: stockInInfo.Manufacturer,
  8755. Dealer: stockInInfo.Dealer,
  8756. LicenseNumber: stockInInfo.LicenseNumber,
  8757. IsEdit: 2,
  8758. Creator: creater,
  8759. SystemTime: record_time,
  8760. ConsumableType: 3,
  8761. WarehousingDetailId: 0,
  8762. IsSys: 1,
  8763. UpdateCreator: creater,
  8764. PatientId: patient_id,
  8765. ReturnCount: delete_count,
  8766. StorehouseId: houseConfig.StorehouseOutInfo,
  8767. }
  8768. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8769. if errflows == gorm.ErrRecordNotFound {
  8770. //创建流水表
  8771. service.CreateStockFlowOne(stockFlow)
  8772. } else if errflows == nil {
  8773. stockFlow := models.VmStockFlow{
  8774. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8775. ID: exsit.ID,
  8776. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8777. WarehouseOutId: warehouseOut.ID,
  8778. GoodId: good_yc.GoodId,
  8779. Number: warehouseOutInfos.Number,
  8780. ProductDate: stockInInfo.ProductDate,
  8781. ExpireDate: stockInInfo.ExpiryDate,
  8782. Count: exsit.Count - delete_count,
  8783. Price: stockInInfo.Price,
  8784. Status: 1,
  8785. Ctime: time.Now().Unix(),
  8786. UserOrgId: good_yc.OrgId,
  8787. Manufacturer: stockInInfo.Manufacturer,
  8788. Dealer: stockInInfo.Dealer,
  8789. LicenseNumber: stockInInfo.LicenseNumber,
  8790. IsEdit: 2,
  8791. Creator: creater,
  8792. SystemTime: record_time,
  8793. ConsumableType: 3,
  8794. WarehousingDetailId: 0,
  8795. IsSys: 1,
  8796. UpdateCreator: creater,
  8797. PatientId: patient_id,
  8798. ReturnCount: delete_count,
  8799. StorehouseId: houseConfig.StorehouseOutInfo,
  8800. }
  8801. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8802. }
  8803. }
  8804. //更改自动出库的表格
  8805. details := models.BloodAutomaticReduceDetail{
  8806. WarehouseOutId: warehouseOutInfo.ID,
  8807. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8808. PatientId: patient_id,
  8809. Ctime: time.Now().Unix(),
  8810. Mtime: time.Now().Unix(),
  8811. Status: 1,
  8812. RecordTime: record_time,
  8813. OrgId: orgID,
  8814. GoodId: good_yc.GoodId,
  8815. GoodTypeId: good_yc.GoodTypeId,
  8816. Count: count,
  8817. StorehouseId: houseConfig.StorehouseOutInfo,
  8818. }
  8819. //查询当天耗材是否已经存在数据
  8820. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8821. if errcode == gorm.ErrRecordNotFound {
  8822. errTwo := service.CreateAutoReduceRecord(&details)
  8823. if errTwo != nil {
  8824. return errTwo
  8825. }
  8826. } else if errcode == nil {
  8827. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8828. service.CreateAutoReduceRecord(&details)
  8829. }
  8830. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8831. //增加出库库存数量
  8832. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8833. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8834. fmt.Println("errOne", errOne)
  8835. // 删除出库完成后,要增加对应批次的库存数量
  8836. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8837. if errThree != nil {
  8838. return errThree
  8839. }
  8840. if good_yc.Count == 0 {
  8841. return nil
  8842. } else {
  8843. return errors.New("退库和出库数据不匹配")
  8844. }
  8845. }
  8846. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8847. //查询该患者当天已经出库的耗材信息
  8848. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8849. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8850. for i := len(goods_yc) - 1; i >= 0; i-- {
  8851. goods_yc_temp := goods_yc[i]
  8852. for j := len(goods) - 1; j >= 0; j-- {
  8853. goods_temp := goods[j]
  8854. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8855. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8856. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8857. if goods_yc_temp.Count == goods_temp.Count {
  8858. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8859. goods = append(goods[:j], goods[j+1:]...)
  8860. break
  8861. }
  8862. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8863. if goods_yc_temp.Count > goods_temp.Count {
  8864. temp_count := goods_yc_temp.Count - goods_temp.Count
  8865. goods_yc[i].Count = temp_count
  8866. goods = append(goods[:j], goods[j+1:]...)
  8867. break
  8868. }
  8869. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8870. if goods_yc_temp.Count < goods_temp.Count {
  8871. temp_count := goods_temp.Count - goods_yc_temp.Count
  8872. goods[j].Count = temp_count
  8873. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8874. break
  8875. }
  8876. }
  8877. }
  8878. }
  8879. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8880. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8881. fmt.Println("剩余需要出库的", len(goods))
  8882. if len(goods) > 0 {
  8883. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8884. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8885. if err == gorm.ErrRecordNotFound {
  8886. //没有记录,则创建出库单
  8887. timeStr := time.Now().Format("2006-01-02")
  8888. timeArr := strings.Split(timeStr, "-")
  8889. total, _ := service.FindAllWarehouseOut(orgID)
  8890. total = total + 1
  8891. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8892. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8893. number = number + total
  8894. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8895. warehouseOut := models.WarehouseOut{
  8896. WarehouseOutOrderNumber: warehousing_out_order,
  8897. OperationTime: time.Now().Unix(),
  8898. OrgId: orgID,
  8899. Creater: creater,
  8900. Ctime: time.Now().Unix(),
  8901. Status: 1,
  8902. WarehouseOutTime: record_time,
  8903. Dealer: 0,
  8904. Manufacturer: 0,
  8905. Type: 1,
  8906. IsSys: 1,
  8907. StorehouseId: houseConfig.StorehouseOutInfo,
  8908. IsCheck: 1,
  8909. }
  8910. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  8911. if err != nil {
  8912. utils.TraceLog("创建出库单失败 err = %v", err)
  8913. return err
  8914. } else {
  8915. out = warehouseOut
  8916. }
  8917. }
  8918. for _, item := range goods {
  8919. var newCount int64 = 0
  8920. for _, it := range goodOne {
  8921. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8922. newCount = it.Count
  8923. }
  8924. }
  8925. prepare := models.DialysisBeforePrepare{
  8926. GoodTypeId: item.GoodTypeId,
  8927. GoodId: item.GoodId,
  8928. Count: item.Count,
  8929. StorehouseId: houseConfig.StorehouseOutInfo,
  8930. }
  8931. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8932. //增加出库数量
  8933. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8934. }
  8935. }
  8936. if len(goods_yc) > 0 {
  8937. for _, good_yc := range goods_yc {
  8938. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8939. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8940. }
  8941. }
  8942. return nil
  8943. }
  8944. // 耗材出库删除
  8945. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8946. // 先根据相关信息查询当天该耗材的出库信息
  8947. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8948. if err != nil {
  8949. return err
  8950. }
  8951. var delete_count int64 = 0
  8952. for _, ware := range warehouseOutInfos {
  8953. // 判断当前出库的数据和删除出库数量
  8954. if good_yc.Count <= ware.Count {
  8955. delete_count = good_yc.Count
  8956. } else {
  8957. delete_count = ware.Count
  8958. }
  8959. warehouseOutInfo := &models.WarehouseOutInfo{
  8960. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8961. WarehouseOutId: warehouseOut.ID,
  8962. Status: 1,
  8963. Ctime: time.Now().Unix(),
  8964. Remark: "",
  8965. OrgId: orgID,
  8966. Type: 1,
  8967. Manufacturer: 0,
  8968. Dealer: 0,
  8969. IsSys: 0,
  8970. SysRecordTime: record_time,
  8971. GoodTypeId: good_yc.GoodTypeId,
  8972. GoodId: good_yc.GoodId,
  8973. StorehouseId: warehouseOut.StorehouseId,
  8974. IsCheck: 1,
  8975. }
  8976. warehouseOutInfo.Count = delete_count
  8977. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8978. warehouseOutInfo.Price = stockInInfo.Price
  8979. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8980. if errOne != nil {
  8981. return errOne
  8982. }
  8983. // 删除出库完成后,要改变流水库存(有疑问)
  8984. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8985. fmt.Println("errOne", errOne)
  8986. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8987. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8988. //扣减出库数量
  8989. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8990. if errThree != nil {
  8991. return errThree
  8992. }
  8993. }
  8994. if good_yc.Count == 0 {
  8995. return nil
  8996. } else {
  8997. return errors.New("退库和出库数据不匹配")
  8998. }
  8999. }
  9000. func (this *DialysisAPIController) GetMobileScheduleList() {
  9001. limit, _ := this.GetInt64("limit")
  9002. page, _ := this.GetInt64("page")
  9003. type_options_visible, _ := this.GetInt64("type_options_visible")
  9004. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  9005. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  9006. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  9007. }
  9008. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  9009. newArr = make([]*models.HisPrescriptionProject, 0)
  9010. for i := 0; i < len(arr); i++ {
  9011. repeat := false
  9012. for j := i + 1; j < len(arr); j++ {
  9013. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  9014. repeat = true
  9015. break
  9016. }
  9017. }
  9018. if !repeat {
  9019. newArr = append(newArr, arr[i])
  9020. }
  9021. }
  9022. return
  9023. }
  9024. func (this *DialysisAPIController) GetRoleList() {
  9025. admin_user_id, _ := this.GetInt64("admin_user_id")
  9026. orgid := this.GetMobileAdminUserInfo().Org.Id
  9027. list, err := service.GetRoleList(orgid, admin_user_id)
  9028. fmt.Println(err)
  9029. this.ServeSuccessJSON(map[string]interface{}{
  9030. "list": list,
  9031. })
  9032. return
  9033. }
  9034. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  9035. // 先根据相关信息查询当天该耗材的出库信息
  9036. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  9037. if err != nil {
  9038. return err
  9039. }
  9040. var delete_count int64 = 0
  9041. delete_count = warehouseOutInfos.Count - count
  9042. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  9043. // 删除出库完成后,要增加对应批次的库存数量
  9044. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  9045. if errThree != nil {
  9046. return errThree
  9047. }
  9048. //增加退库数量
  9049. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  9050. //扣减出库数量
  9051. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  9052. //查询剩余库存
  9053. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  9054. var sum_count int64
  9055. for _, item := range goodList {
  9056. sum_count += item.StockCount
  9057. }
  9058. // 在出库记录表里记录退库详情
  9059. warehouseOutInfo := &models.WarehouseOutInfo{
  9060. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9061. WarehouseOutId: warehouseOut.ID,
  9062. Status: 1,
  9063. Ctime: time.Now().Unix(),
  9064. OrgId: orgID,
  9065. Type: 1,
  9066. IsSys: 1,
  9067. SysRecordTime: record_time,
  9068. GoodTypeId: good_yc.GoodTypeId,
  9069. GoodId: good_yc.GoodId,
  9070. PatientId: good_yc.PatientId,
  9071. ConsumableType: 2,
  9072. StorehouseId: houseConfig.StorehouseOutInfo,
  9073. IsCheck: 1,
  9074. OverCount: sum_count,
  9075. }
  9076. warehouseOutInfo.Count = count
  9077. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  9078. warehouseOutInfo.Price = stockInInfo.Price
  9079. warehouseOutInfo.Dealer = stockInInfo.Dealer
  9080. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  9081. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  9082. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  9083. warehouseOutInfo.Number = warehouseOutInfos.Number
  9084. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  9085. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  9086. //查找当天是否存在出库记录
  9087. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9088. if errcod == gorm.ErrRecordNotFound {
  9089. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  9090. //插入详情明细表
  9091. if errOne != nil {
  9092. return errOne
  9093. }
  9094. //插入详情明细表
  9095. stockFlow := models.VmStockFlow{
  9096. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9097. WarehouseOutId: warehouseOut.ID,
  9098. GoodId: good_yc.GoodId,
  9099. Number: warehouseOutInfos.Number,
  9100. ProductDate: stockInInfo.ProductDate,
  9101. ExpireDate: stockInInfo.ExpiryDate,
  9102. Count: count,
  9103. Price: stockInInfo.Price,
  9104. Status: 1,
  9105. Ctime: record_time,
  9106. UserOrgId: good_yc.OrgId,
  9107. Manufacturer: stockInInfo.Manufacturer,
  9108. Dealer: stockInInfo.Dealer,
  9109. LicenseNumber: stockInInfo.LicenseNumber,
  9110. IsEdit: 2,
  9111. Creator: creater,
  9112. SystemTime: record_time,
  9113. ConsumableType: 3,
  9114. WarehousingDetailId: 0,
  9115. IsSys: 1,
  9116. UpdateCreator: creater,
  9117. PatientId: patient_id,
  9118. StorehouseId: houseConfig.StorehouseOutInfo,
  9119. OverCount: sum_count,
  9120. ProjectId: good_yc.ProjectId,
  9121. }
  9122. err := service.CreateStockFlowOne(stockFlow)
  9123. fmt.Println("err", err)
  9124. } else if errcod == nil {
  9125. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9126. }
  9127. //创建退库单
  9128. operation_time := time.Now().Unix()
  9129. //创建退库单
  9130. timeStr := time.Now().Format("2006-01-02")
  9131. timeArr := strings.Split(timeStr, "-")
  9132. total, _ := service.FindAllCancelStockTotal(orgID)
  9133. total = total + 1
  9134. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9135. cancelStock := models.CancelStock{
  9136. OrderNumber: orderNumber,
  9137. OperaTime: operation_time,
  9138. OrgId: orgID,
  9139. Creater: warehouseOut.Creater,
  9140. Ctime: time.Now().Unix(),
  9141. Status: 1,
  9142. ReturnTime: record_time,
  9143. Type: 1,
  9144. StorehouseId: stockInInfo.StorehouseId,
  9145. IsCheck: 1,
  9146. }
  9147. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  9148. if msgerrkonde == gorm.ErrRecordNotFound {
  9149. service.AddSigleCancelStock(&cancelStock)
  9150. }
  9151. cancel, _ := service.GetLastCancelStockById(orgID)
  9152. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  9153. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  9154. cancelStockInfo := models.CancelStockInfo{
  9155. GoodId: stockInInfo.GoodId,
  9156. CancelStockId: cancel.ID,
  9157. GoodTypeId: stockInInfo.GoodTypeId,
  9158. Count: delete_count,
  9159. Price: stockInInfo.PackingPrice,
  9160. Total: 0,
  9161. ProductDate: stockInInfo.ProductDate,
  9162. ExpiryDate: stockInInfo.ExpiryDate,
  9163. Ctime: record_time,
  9164. Status: 1,
  9165. OrgId: orgID,
  9166. OrderNumber: cancel.OrderNumber,
  9167. Type: 0,
  9168. Dealer: deaerler.DealerName,
  9169. Manufacturer: manufacturer.ManufacturerName,
  9170. Number: stockInInfo.Number,
  9171. RegisterAccount: "",
  9172. Remark: "",
  9173. WarehouseInfoId: stockInInfo.ID,
  9174. PatientId: patient_id,
  9175. RecordDate: record_time,
  9176. StorehouseId: stockInInfo.StorehouseId,
  9177. IsCheck: 1,
  9178. }
  9179. service.CreateCancelStockInfoOne(&cancelStockInfo)
  9180. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  9181. flow := models.VmStockFlow{
  9182. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  9183. GoodId: good_yc.GoodId,
  9184. Number: warehouseOutInfos.Number,
  9185. LicenseNumber: stockInInfo.LicenseNumber,
  9186. Count: delete_count,
  9187. UserOrgId: orgID,
  9188. PatientId: patient_id,
  9189. SystemTime: record_time,
  9190. ConsumableType: 7,
  9191. IsSys: 0,
  9192. WarehousingOrder: "",
  9193. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  9194. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9195. IsEdit: 0,
  9196. CancelStockId: cancel.ID,
  9197. CancelOrderNumber: cancel.OrderNumber,
  9198. Manufacturer: manufacturer.ID,
  9199. Dealer: 0,
  9200. Creator: warehouseOut.Creater,
  9201. UpdateCreator: 0,
  9202. Status: 1,
  9203. Ctime: record_time,
  9204. Mtime: 0,
  9205. Price: stockInInfo.Price,
  9206. WarehousingDetailId: stockInInfo.ID,
  9207. WarehouseOutDetailId: warehouseOutInfos.ID,
  9208. CancelOutDetailId: cancelInfo.ID,
  9209. ProductDate: stockInInfo.ProductDate,
  9210. ExpireDate: stockInInfo.ExpiryDate,
  9211. StorehouseId: houseConfig.StorehouseOutInfo,
  9212. OverCount: sum_count,
  9213. }
  9214. service.CreateStockFlowOne(flow)
  9215. //更改自动出库的表格
  9216. details := models.BloodAutomaticReduceDetail{
  9217. WarehouseOutId: warehouseOutInfo.ID,
  9218. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9219. PatientId: patient_id,
  9220. Ctime: time.Now().Unix(),
  9221. Mtime: time.Now().Unix(),
  9222. Status: 1,
  9223. RecordTime: record_time,
  9224. OrgId: orgID,
  9225. GoodId: good_yc.GoodId,
  9226. GoodTypeId: good_yc.GoodTypeId,
  9227. Count: count,
  9228. StorehouseId: houseConfig.StorehouseOutInfo,
  9229. }
  9230. //查询当天耗材是否已经存在数据
  9231. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9232. if errcode == gorm.ErrRecordNotFound {
  9233. errTwo := service.CreateAutoReduceRecord(&details)
  9234. if errTwo != nil {
  9235. return errTwo
  9236. }
  9237. } else if errcode == nil {
  9238. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9239. service.CreateAutoReduceRecord(&details)
  9240. }
  9241. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  9242. //增加出库库存数量
  9243. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  9244. if good_yc.Count == 0 {
  9245. return nil
  9246. } else {
  9247. return errors.New("退库和出库数据不匹配")
  9248. }
  9249. }
  9250. func (this *DialysisAPIController) SavePatientSign() {
  9251. adminUserInfo := this.GetMobileAdminUserInfo()
  9252. patient_id, _ := this.GetInt64("patient_id")
  9253. dialysis_date, _ := this.GetInt64("dialysis_date")
  9254. orgid := adminUserInfo.Org.Id
  9255. var esdata models.DialysisOrder
  9256. var err error
  9257. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  9258. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9259. return
  9260. }
  9261. esdata.Hash = esdata.Hash
  9262. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  9263. order := models.DialysisOrder{
  9264. Hash: esdata.Hash,
  9265. Url: esdata.Url,
  9266. }
  9267. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  9268. redis := service.RedisClient()
  9269. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9270. redis.Set(key, "", time.Second)
  9271. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9272. //清空key 值
  9273. redis.Set(keyOne, "", time.Second)
  9274. //scheduleDateStartOne := startDate.Format("2006-01-02")
  9275. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  9276. //redis.Set(keyTwo, "", time.Second)
  9277. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9278. redis.Set(keyThree, "", time.Second)
  9279. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9280. redis.Set(keyFour, "", time.Second)
  9281. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9282. redis.Set(keyFive, "", time.Second)
  9283. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9284. redis.Set(keySix, "", time.Second)
  9285. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  9286. redis.Set(keySeven, "", time.Second)
  9287. if err != nil {
  9288. fmt.Println(err)
  9289. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9290. return
  9291. }
  9292. this.ServeSuccessJSON(map[string]interface{}{
  9293. "electronic_signature": esdata,
  9294. })
  9295. }
  9296. func (this *DialysisAPIController) GetPatientSign() {
  9297. patient_id, _ := this.GetInt64("patient_id")
  9298. dialysis_date, _ := this.GetInt64("dialysis_date")
  9299. adminUserInfo := this.GetMobileAdminUserInfo()
  9300. orgId := adminUserInfo.Org.Id
  9301. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  9302. if err != nil {
  9303. fmt.Println(err)
  9304. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9305. return
  9306. }
  9307. this.ServeSuccessJSON(map[string]interface{}{
  9308. "dialysisOrder": dialysisOrder,
  9309. })
  9310. }
  9311. func (this *DialysisAPIController) GetScheduleByPatient() {
  9312. patient_id, _ := this.GetInt64("patient_id")
  9313. schedule_date, _ := this.GetInt64("schedule_date")
  9314. orgid := this.GetMobileAdminUserInfo().Org.Id
  9315. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  9316. this.ServeSuccessJSON(map[string]interface{}{
  9317. "schedule": schedule,
  9318. })
  9319. }
  9320. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  9321. org_id := this.GetMobileAdminUserInfo().Org.Id
  9322. patient_id, _ := this.GetInt64("patient_id")
  9323. schedule_date, _ := this.GetInt64("schedule_date")
  9324. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  9325. this.ServeSuccessJSON(map[string]interface{}{
  9326. "order": order,
  9327. })
  9328. }
  9329. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  9330. org_id := this.GetMobileAdminUserInfo().Org.Id
  9331. schedule_date := this.GetString("schedule_date")
  9332. schedule_type, _ := this.GetInt64("schedule_type")
  9333. timeLayout := "2006-01-02"
  9334. loc, _ := time.LoadLocation("Local")
  9335. var startdateunix int64
  9336. if len(schedule_date) > 0 {
  9337. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  9338. if err != nil {
  9339. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9340. return
  9341. }
  9342. startdateunix = theTime.Unix()
  9343. }
  9344. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  9345. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  9346. devices, _ := service.GetAllDevicetByListSix(org_id)
  9347. for key, item := range scheduals {
  9348. // 床位信息
  9349. for _, device := range devices {
  9350. if item.BedId == device.ID {
  9351. scheduals[key].DeviceNumber = device
  9352. break
  9353. }
  9354. }
  9355. }
  9356. this.ServeSuccessJSON(map[string]interface{}{
  9357. "list": list,
  9358. "scheduals": scheduals,
  9359. })
  9360. }
  9361. func (this *DialysisAPIController) SavePatientPicture() {
  9362. patient_id, _ := this.GetInt64("patient_id")
  9363. dialysis_date, _ := this.GetInt64("schedule_date")
  9364. avatar := this.GetString("avatar")
  9365. fmt.Println("patient_id", patient_id)
  9366. orgId := this.GetMobileAdminUserInfo().Org.Id
  9367. order := models.DialysisOrder{
  9368. Url: avatar,
  9369. }
  9370. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  9371. redis := service.RedisClient()
  9372. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9373. redis.Set(key, "", time.Second)
  9374. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9375. //清空key 值
  9376. redis.Set(keyOne, "", time.Second)
  9377. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9378. redis.Set(keyThree, "", time.Second)
  9379. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9380. redis.Set(keyFour, "", time.Second)
  9381. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9382. redis.Set(keyFive, "", time.Second)
  9383. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9384. redis.Set(keySix, "", time.Second)
  9385. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  9386. redis.Set(keySeven, "", time.Second)
  9387. if err != nil {
  9388. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9389. return
  9390. }
  9391. this.ServeSuccessJSON(map[string]interface{}{
  9392. "order": order,
  9393. })
  9394. }
  9395. func (this *DialysisAPIController) ExectionMobileAdvice() {
  9396. ids := this.GetString("ids")
  9397. idSplit := strings.Split(ids, ",")
  9398. orgId := this.GetMobileAdminUserInfo().Org.Id
  9399. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9400. execution_time := this.GetString("exce_time")
  9401. timeLayout2 := "2006-01-02 15:04:05"
  9402. loc, _ := time.LoadLocation("Local")
  9403. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  9404. if errs != nil {
  9405. utils.ErrorLog(errs.Error())
  9406. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9407. return
  9408. }
  9409. //his客户
  9410. if config.IsOpen == 1 {
  9411. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  9412. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  9413. for _, item := range list {
  9414. for _, it := range adviceList {
  9415. if item.DrugId == it.DrugId {
  9416. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9417. }
  9418. }
  9419. }
  9420. for _, item := range list {
  9421. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9422. var sum_out_count int64
  9423. for _, itemThree := range item.ChildDoctorAdvice {
  9424. var prescribing_number int64
  9425. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9426. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9427. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9428. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9429. }
  9430. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9431. prescribing_number = parseIntPrescribingNumber
  9432. }
  9433. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9434. prescribing_number = parseIntPrescribingNumber
  9435. }
  9436. sum_out_count += prescribing_number
  9437. }
  9438. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9439. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9440. //库存不足
  9441. if sum_out_count > drugStockOut.FlushCount {
  9442. this.ServeSuccessJSON(map[string]interface{}{
  9443. "msg": "2",
  9444. "drug": medical,
  9445. "ids": ids,
  9446. })
  9447. return
  9448. }
  9449. }
  9450. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9451. //执行医嘱
  9452. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9453. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9454. for _, item := range advices {
  9455. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9456. redis := service.RedisClient()
  9457. //清空key 值
  9458. redis.Set(key, "", time.Second)
  9459. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9460. redis.Set(keyTwo, "", time.Second)
  9461. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9462. redis.Set(keyThree, "", time.Second)
  9463. recordDate := theTime.Format("2006-01-02")
  9464. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9465. redis.Set(keyFour, "", time.Second)
  9466. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9467. redis.Set(keyFive, "", time.Second)
  9468. defer redis.Close()
  9469. }
  9470. if errs == nil {
  9471. //药品管理信息
  9472. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9473. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9474. if drugStockConfig.IsOpen == 1 {
  9475. for _, item := range advices {
  9476. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9477. config, _ := service.GetDrugOpenConfigOne(orgId)
  9478. if config.IsOpen != 1 {
  9479. //查询该药品是否有库存
  9480. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9481. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9482. if medical.IsUse == 2 {
  9483. if config.IsOpen != 1 {
  9484. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9485. service.HisDrugsDelivery(orgId, creater, &advice)
  9486. if orgId == 3877 || orgId == 10265 {
  9487. //查询该药品是否有出库记录
  9488. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9489. if len(flowMap) == 0 {
  9490. errs := service.UpdateHisAdviceById(advice.ID)
  9491. if errs != nil {
  9492. drugError := models.XtDrugError{
  9493. UserOrgId: orgId,
  9494. DrugId: item.DrugId,
  9495. RecordDate: item.AdviceDate,
  9496. PatientId: item.PatientId,
  9497. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9498. Status: 1,
  9499. Ctime: time.Now().Unix(),
  9500. Mtime: 0,
  9501. SumCount: 0,
  9502. Prescribingnumber: advice.PrescribingNumber,
  9503. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9504. }
  9505. service.CreateDrugError(drugError)
  9506. }
  9507. this.ServeSuccessJSON(map[string]interface{}{
  9508. "msg": "2",
  9509. "drug": medical,
  9510. "ids": ids,
  9511. })
  9512. return
  9513. }
  9514. }
  9515. }
  9516. if pharmacyConfig.IsOpen != 1 {
  9517. service.HisDrugsDelivery(orgId, creater, &advice)
  9518. if orgId == 3877 || orgId == 10265 {
  9519. //查询该药品是否有出库记录
  9520. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9521. if len(flowMap) == 0 {
  9522. errs := service.UpdateHisAdviceById(advice.ID)
  9523. if errs != nil {
  9524. drugError := models.XtDrugError{
  9525. UserOrgId: orgId,
  9526. DrugId: item.DrugId,
  9527. RecordDate: item.AdviceDate,
  9528. PatientId: item.PatientId,
  9529. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9530. Status: 1,
  9531. Ctime: time.Now().Unix(),
  9532. Mtime: 0,
  9533. SumCount: 0,
  9534. Prescribingnumber: advice.PrescribingNumber,
  9535. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9536. }
  9537. service.CreateDrugError(drugError)
  9538. }
  9539. this.ServeSuccessJSON(map[string]interface{}{
  9540. "msg": "2",
  9541. "drug": medical,
  9542. "ids": ids,
  9543. })
  9544. return
  9545. }
  9546. }
  9547. }
  9548. //更新字典里面的库存
  9549. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9550. var sum_count int64
  9551. for _, its := range stockInfo {
  9552. if its.MaxUnit == medical.MaxUnit {
  9553. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9554. }
  9555. sum_count += its.StockMaxNumber + its.StockMinNumber
  9556. }
  9557. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9558. //剩余库存
  9559. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9560. }
  9561. }
  9562. }
  9563. }
  9564. }
  9565. this.ServeSuccessJSON(map[string]interface{}{
  9566. "msg": "1",
  9567. "ids": ids,
  9568. })
  9569. return
  9570. } else {
  9571. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9572. }
  9573. }
  9574. //血透客户
  9575. if config.IsOpen == 2 || config.IsOpen == 0 {
  9576. //药品管理信息
  9577. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9578. if drugStockConfig.IsOpen == 1 {
  9579. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9580. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9581. for _, item := range list {
  9582. for _, it := range adviceList {
  9583. if item.DrugId == it.DrugId {
  9584. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9585. }
  9586. }
  9587. }
  9588. for _, item := range list {
  9589. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9590. var sum_out_count int64
  9591. for _, itemThree := range item.ChildDoctorAdvice {
  9592. var prescribing_number int64
  9593. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9594. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9595. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9596. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9597. }
  9598. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9599. prescribing_number = parseIntPrescribingNumber
  9600. }
  9601. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9602. prescribing_number = parseIntPrescribingNumber
  9603. }
  9604. sum_out_count += prescribing_number
  9605. }
  9606. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9607. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9608. //库存不足
  9609. if sum_out_count > drugStockOut.FlushCount {
  9610. this.ServeSuccessJSON(map[string]interface{}{
  9611. "msg": "2",
  9612. "drug": medical,
  9613. "ids": ids,
  9614. })
  9615. return
  9616. }
  9617. }
  9618. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9619. //执行医嘱
  9620. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9621. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9622. for _, item := range advices {
  9623. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9624. redis := service.RedisClient()
  9625. //清空key 值
  9626. redis.Set(key, "", time.Second)
  9627. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9628. redis.Set(keyTwo, "", time.Second)
  9629. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9630. redis.Set(keyThree, "", time.Second)
  9631. recordDate := theTime.Format("2006-01-02")
  9632. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9633. redis.Set(keyFour, "", time.Second)
  9634. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9635. redis.Set(keyFive, "", time.Second)
  9636. defer redis.Close()
  9637. }
  9638. if errs == nil {
  9639. for _, item := range advices {
  9640. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9641. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9642. //查询是否出库按钮开启
  9643. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9644. if adviceSetting.IsAdviceOpen == 1 {
  9645. //查询是否出库按钮开启
  9646. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9647. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9648. if prescriptionConfig.IsOpen == 1 {
  9649. if medical.IsUse == 2 {
  9650. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9651. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9652. }
  9653. if pharmacyConfig.IsOpen != 1 {
  9654. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9655. }
  9656. //更新字典里面的库存
  9657. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9658. var sum_count int64
  9659. for _, its := range stockInfo {
  9660. if its.MaxUnit == medical.MaxUnit {
  9661. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9662. }
  9663. sum_count += its.StockMaxNumber + its.StockMinNumber
  9664. }
  9665. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9666. //剩余库存
  9667. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9668. }
  9669. }
  9670. } else {
  9671. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9672. if medical.IsUse == 2 {
  9673. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9674. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9675. }
  9676. if pharmacyConfig.IsOpen != 1 {
  9677. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9678. }
  9679. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9680. var sum_count int64
  9681. for _, its := range stockInfo {
  9682. if its.MaxUnit == medical.MaxUnit {
  9683. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9684. }
  9685. sum_count += its.StockMaxNumber + its.StockMinNumber
  9686. }
  9687. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9688. //剩余库存
  9689. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9690. }
  9691. }
  9692. }
  9693. }
  9694. this.ServeSuccessJSON(map[string]interface{}{
  9695. "msg": "1",
  9696. "ids": ids,
  9697. })
  9698. return
  9699. } else {
  9700. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9701. //执行医嘱
  9702. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9703. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9704. for _, item := range advices {
  9705. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9706. redis := service.RedisClient()
  9707. //清空key 值
  9708. redis.Set(key, "", time.Second)
  9709. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9710. redis.Set(keyTwo, "", time.Second)
  9711. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9712. redis.Set(keyThree, "", time.Second)
  9713. recordDate := theTime.Format("2006-01-02")
  9714. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9715. redis.Set(keyFour, "", time.Second)
  9716. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9717. redis.Set(keyFive, "", time.Second)
  9718. defer redis.Close()
  9719. }
  9720. this.ServeSuccessJSON(map[string]interface{}{
  9721. "msg": "1",
  9722. "ids": ids,
  9723. })
  9724. return
  9725. }
  9726. }
  9727. }
  9728. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9729. ids := this.GetString("ids")
  9730. idSplit := strings.Split(ids, ",")
  9731. orgId := this.GetMobileAdminUserInfo().Org.Id
  9732. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9733. if config.IsOpen == 1 {
  9734. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9735. this.ServeSuccessJSON(map[string]interface{}{
  9736. "msg": "1",
  9737. "ids": ids,
  9738. })
  9739. return
  9740. }
  9741. if config.IsOpen == 0 || config.IsOpen == 2 {
  9742. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9743. this.ServeSuccessJSON(map[string]interface{}{
  9744. "msg": "1",
  9745. "ids": ids,
  9746. })
  9747. return
  9748. }
  9749. }
  9750. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9751. ids := this.GetString("ids")
  9752. idSplit := strings.Split(ids, ",")
  9753. orgId := this.GetMobileAdminUserInfo().Org.Id
  9754. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9755. //his
  9756. if config.IsOpen == 1 {
  9757. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9758. theTime := time.Now()
  9759. advices := models.HisDoctorAdviceThirty{
  9760. CheckTime: theTime.Unix(),
  9761. Checker: checker,
  9762. UpdatedTime: time.Now().Unix(),
  9763. }
  9764. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9765. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9766. for _, item := range list {
  9767. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9768. redis := service.RedisClient()
  9769. //清空key 值
  9770. redis.Set(key, "", time.Second)
  9771. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9772. redis.Set(keyTwo, "", time.Second)
  9773. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9774. redis.Set(keyThree, "", time.Second)
  9775. recordDate := theTime.Format("2006-01-02")
  9776. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9777. redis.Set(keyFour, "", time.Second)
  9778. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9779. redis.Set(keyFive, "", time.Second)
  9780. defer redis.Close()
  9781. }
  9782. this.ServeSuccessJSON(map[string]interface{}{
  9783. "msg": "1",
  9784. "ids": ids,
  9785. })
  9786. return
  9787. }
  9788. //血透
  9789. if config.IsOpen == 0 || config.IsOpen == 2 {
  9790. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9791. theTime := time.Now()
  9792. advices := models.DoctorAdvice{
  9793. CheckTime: theTime.Unix(),
  9794. Checker: checker,
  9795. UpdatedTime: time.Now().Unix(),
  9796. }
  9797. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9798. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9799. for _, item := range list {
  9800. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9801. redis := service.RedisClient()
  9802. //清空key 值
  9803. redis.Set(key, "", time.Second)
  9804. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9805. redis.Set(keyTwo, "", time.Second)
  9806. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9807. redis.Set(keyThree, "", time.Second)
  9808. recordDate := theTime.Format("2006-01-02")
  9809. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9810. redis.Set(keyFour, "", time.Second)
  9811. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9812. redis.Set(keyFive, "", time.Second)
  9813. defer redis.Close()
  9814. }
  9815. this.ServeSuccessJSON(map[string]interface{}{
  9816. "msg": "1",
  9817. "ids": ids,
  9818. })
  9819. return
  9820. }
  9821. }
  9822. func (this *DialysisAPIController) CheckSchedule() {
  9823. patientID, _ := this.GetInt64("patient_id")
  9824. recordDateStr := this.GetString("record_date")
  9825. nurseID, _ := this.GetInt64("start_nurse")
  9826. schedual_type, _ := this.GetInt64("schedual_type")
  9827. bedID, _ := this.GetInt64("bed")
  9828. start_time := this.GetString("start_time")
  9829. fmt.Println("patientID", patientID)
  9830. fmt.Println("recordDateStr", recordDateStr)
  9831. fmt.Println("nurseID", nurseID)
  9832. fmt.Println("schedual_type------", schedual_type)
  9833. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9834. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9835. return
  9836. }
  9837. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9838. if parseStartDateErr != nil {
  9839. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9840. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9841. return
  9842. }
  9843. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9844. if parseErr != nil {
  9845. this.ErrorLog("时间解析失败:%v", parseErr)
  9846. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9847. return
  9848. }
  9849. adminUserInfo := this.GetMobileAdminUserInfo()
  9850. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9851. if getPatientErr != nil {
  9852. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9853. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9854. return
  9855. } else if patient == nil {
  9856. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9857. return
  9858. }
  9859. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9860. if getNurseErr != nil {
  9861. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9862. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9863. return
  9864. } else if nurse == nil {
  9865. this.ErrorLog("护士不存在")
  9866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9867. return
  9868. }
  9869. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9870. if getDeviceNumberErr != nil {
  9871. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9872. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9873. return
  9874. } else if deviceNumber == nil {
  9875. this.ErrorLog("床位号不存在")
  9876. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9877. return
  9878. }
  9879. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9880. if getRecordErr != nil {
  9881. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9882. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9883. return
  9884. } else if dialysisRecord != nil {
  9885. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9886. return
  9887. }
  9888. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9889. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9890. timeLayout := "2006-01-02 15:04:05"
  9891. loc, _ := time.LoadLocation("Local")
  9892. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9893. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9894. schedulestartTime := theStartTime.Unix()
  9895. scheduleendTime := theEndTime.Unix()
  9896. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9897. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9898. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9899. //查询该床位是否有人用了
  9900. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9901. if err == nil {
  9902. if schedule.ID == 0 {
  9903. this.ServeSuccessJSON(map[string]interface{}{
  9904. "status": 0,
  9905. "msg": "请求失败",
  9906. })
  9907. } else {
  9908. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9909. if order.ID > 0 { //该机位被其他人占用了
  9910. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9911. return
  9912. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9913. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9914. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9915. this.ServeSuccessJSON(map[string]interface{}{
  9916. "status": 1,
  9917. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9918. })
  9919. return
  9920. } else {
  9921. this.ServeSuccessJSON(map[string]interface{}{
  9922. "status": 0,
  9923. "msg": "",
  9924. })
  9925. }
  9926. }
  9927. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9928. this.ServeSuccessJSON(map[string]interface{}{
  9929. "status": 2,
  9930. "msg": "当前机位已有患者在使用,请重新选择!",
  9931. })
  9932. }
  9933. }
  9934. } else {
  9935. this.ServeSuccessJSON(map[string]interface{}{
  9936. "status": 0,
  9937. "msg": "",
  9938. })
  9939. }
  9940. }
  9941. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9942. orgId := this.GetMobileAdminUserInfo().Org.Id
  9943. schedule_type, _ := this.GetInt64("schedule_type")
  9944. partion_type, _ := this.GetInt64("partion_type")
  9945. start_time := this.GetString("start_time")
  9946. timeLayout := "2006-01-02"
  9947. loc, _ := time.LoadLocation("Local")
  9948. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9949. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9950. _, config := service.FindXTHisRecordByOrgId(orgId)
  9951. appId := this.GetMobileAdminUserInfo().App.Id
  9952. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9953. if err == nil {
  9954. this.ServeSuccessJSON(map[string]interface{}{
  9955. "list": list,
  9956. "config": config,
  9957. "doctorList": doctorList,
  9958. })
  9959. return
  9960. } else {
  9961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9962. return
  9963. }
  9964. }
  9965. func (this *DialysisAPIController) SaveMobileInformation() {
  9966. patient_id, _ := this.GetInt64("patient_id")
  9967. record_date, _ := this.GetInt64("record_date")
  9968. startTime := this.GetString("start_time")
  9969. module, _ := this.GetInt64("module")
  9970. remark := this.GetString("remark")
  9971. timeLayout := "2006-01-02 15:04"
  9972. loc, _ := time.LoadLocation("Local")
  9973. if len(startTime) == 0 {
  9974. utils.ErrorLog("len(start_time) == 0")
  9975. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9976. return
  9977. }
  9978. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9979. if err != nil {
  9980. utils.ErrorLog(err.Error())
  9981. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9982. return
  9983. }
  9984. StartTime := theTime.Unix()
  9985. fmt.Println("startime-------------", StartTime)
  9986. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9987. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9988. information := models.XtDialysisInformation{
  9989. Module: module,
  9990. PatientId: patient_id,
  9991. RecordDate: record_date,
  9992. ApplicationDate: StartTime,
  9993. Creater: creater,
  9994. ApplicationStatus: 2,
  9995. Checker: 0,
  9996. CheckTime: 0,
  9997. Remark: remark,
  9998. UserOrgId: user_org_id,
  9999. Ctime: time.Now().Unix(),
  10000. Status: 1,
  10001. Mtime: 0,
  10002. }
  10003. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  10004. if infor.ID == 0 {
  10005. service.SaveDialysisInformation(information)
  10006. }
  10007. if infor.ID > 0 {
  10008. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  10009. }
  10010. this.ServeSuccessJSON(map[string]interface{}{
  10011. "information": information,
  10012. })
  10013. return
  10014. }
  10015. func (this *DialysisAPIController) GetMobileInformation() {
  10016. limit, _ := this.GetInt64("limit")
  10017. page, _ := this.GetInt64("page")
  10018. orgid := this.GetMobileAdminUserInfo().Org.Id
  10019. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  10020. appid := this.GetMobileAdminUserInfo().App.Id
  10021. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  10022. patients, _ := service.GetAllpatientThirty(orgid)
  10023. this.ServeSuccessJSON(map[string]interface{}{
  10024. "information": information,
  10025. "total": total,
  10026. "doclist": doclist,
  10027. "patients": patients,
  10028. })
  10029. return
  10030. }
  10031. func (this *DialysisAPIController) GetMobileInformationOne() {
  10032. limit, _ := this.GetInt64("limit")
  10033. page, _ := this.GetInt64("page")
  10034. orgid := this.GetMobileAdminUserInfo().Org.Id
  10035. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  10036. appid := this.GetMobileAdminUserInfo().App.Id
  10037. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  10038. patients, _ := service.GetAllpatientThirty(orgid)
  10039. this.ServeSuccessJSON(map[string]interface{}{
  10040. "information": information,
  10041. "total": total,
  10042. "doclist": doclist,
  10043. "patients": patients,
  10044. })
  10045. return
  10046. }
  10047. func (this *DialysisAPIController) CheckMobileInformation() {
  10048. id, _ := this.GetInt64("id")
  10049. application_status, _ := this.GetInt64("application_status")
  10050. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  10051. checktime := time.Now().Unix()
  10052. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  10053. if err == nil {
  10054. this.ServeSuccessJSON(map[string]interface{}{
  10055. "msg": "ok",
  10056. })
  10057. return
  10058. }
  10059. }
  10060. func (c *DialysisAPIController) GetControlMonitorList() {
  10061. partition, _ := c.GetInt64("partition")
  10062. monitorDate := c.GetString("date")
  10063. patient_id, _ := c.GetInt64("patient_id")
  10064. pat_type, _ := c.GetInt64("pat_type")
  10065. timeLayout := "2006-01-02"
  10066. loc, _ := time.LoadLocation("Local")
  10067. var theStartTime int64
  10068. if len(monitorDate) > 0 {
  10069. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  10070. if err != nil {
  10071. theStartTime = 0
  10072. }
  10073. theStartTime = theTime.Unix()
  10074. }
  10075. adminInfo := c.GetMobileAdminUserInfo()
  10076. orgID := adminInfo.Org.Id
  10077. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  10078. if err != nil {
  10079. c.ErrorLog("获取排班信息失败:%v", err)
  10080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10081. } else {
  10082. if len(monitor) > 0 {
  10083. //获取所有床位
  10084. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  10085. //获取所有分区
  10086. zoneList, _ := service.GetAllZoneByList(orgID)
  10087. //获取透析处方
  10088. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  10089. //获取透前评估
  10090. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  10091. //获取上机
  10092. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  10093. //获取透后
  10094. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  10095. //获取透后监测
  10096. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  10097. //获取所有的患者
  10098. patients, _ := service.GetAllPatientListByListOne(orgID)
  10099. //获取所有透析模式
  10100. treatments, _ := service.GetAllTreatModeByList(orgID)
  10101. //获取所有医嘱
  10102. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  10103. //获取双人核对
  10104. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  10105. //治疗小结
  10106. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  10107. //待消毒
  10108. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  10109. for key, item := range monitor {
  10110. // 获取床位信息
  10111. for _, it := range numberList {
  10112. if item.BedId == it.ID {
  10113. monitor[key].DeviceNumber = it
  10114. break
  10115. }
  10116. }
  10117. //获取分区信息
  10118. for _, it := range zoneList {
  10119. if item.PartitionId == it.ID {
  10120. monitor[key].DeviceZone = it
  10121. }
  10122. }
  10123. for _, prescription := range prescriptions {
  10124. if item.PatientId == prescription.PatientId {
  10125. monitor[key].Prescription = prescription
  10126. break
  10127. }
  10128. }
  10129. for _, it := range checkList {
  10130. if item.PatientId == it.PatientId {
  10131. monitor[key].DoubleCheck = it
  10132. break
  10133. }
  10134. }
  10135. for _, it := range summaryList {
  10136. if item.PatientId == it.PatientId {
  10137. monitor[key].TreatmentSummaryForList = it
  10138. break
  10139. }
  10140. }
  10141. // 透前评估
  10142. for _, assessmentBefore := range assessmentBefores {
  10143. if item.PatientId == assessmentBefore.PatientId {
  10144. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  10145. break
  10146. }
  10147. }
  10148. // 透析上下机
  10149. for _, dialysisOrder := range dialysisOrders {
  10150. if item.PatientId == dialysisOrder.PatientId {
  10151. monitor[key].DialysisOrder = dialysisOrder
  10152. break
  10153. }
  10154. }
  10155. // 治疗小节
  10156. for _, afterDislysis := range AssessmentAfterDislysis {
  10157. if item.PatientId == afterDislysis.PatientId {
  10158. monitor[key].AssessmentAfterDislysis = afterDislysis
  10159. break
  10160. }
  10161. }
  10162. for _, it := range monitorlist {
  10163. if item.PatientId == it.PatientId {
  10164. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  10165. }
  10166. }
  10167. for _, it := range adviceList {
  10168. if item.PatientId == it.PatientId {
  10169. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  10170. }
  10171. }
  10172. for _, patient := range patients {
  10173. if item.PatientId == patient.ID {
  10174. monitor[key].MonitorPatients = patient
  10175. break
  10176. }
  10177. }
  10178. for _, treatment := range treatments {
  10179. if item.ModeId == treatment.ID {
  10180. monitor[key].TreatmentMode = treatment
  10181. break
  10182. }
  10183. }
  10184. for _, infor := range informationList {
  10185. if item.PatientId == infor.PatientId {
  10186. monitor[key].NewDeviceInformation = infor
  10187. break
  10188. }
  10189. }
  10190. }
  10191. }
  10192. }
  10193. patients, err := service.GetAllpatientFourty(orgID)
  10194. var mds []*models.NewMonitorDialysisScheduleList
  10195. if pat_type == 0 {
  10196. for _, item := range monitor {
  10197. mds = append(mds, item)
  10198. }
  10199. }
  10200. //待医嘱核对
  10201. if pat_type == 1 {
  10202. for _, item := range monitor {
  10203. if len(item.AdviceList) > 0 {
  10204. mds = append(mds, item)
  10205. }
  10206. }
  10207. }
  10208. //待开小结
  10209. if pat_type == 2 {
  10210. for _, item := range monitor {
  10211. if item.TreatmentSummaryForList == nil {
  10212. mds = append(mds, item)
  10213. }
  10214. }
  10215. }
  10216. //待下机
  10217. if pat_type == 3 {
  10218. for _, item := range monitor {
  10219. if item.DialysisOrder != nil {
  10220. if item.DialysisOrder.ID > 0 {
  10221. mds = append(mds, item)
  10222. }
  10223. }
  10224. }
  10225. }
  10226. //待消毒
  10227. if pat_type == 4 {
  10228. for _, item := range monitor {
  10229. if item.NewDeviceInformation == nil {
  10230. mds = append(mds, item)
  10231. }
  10232. }
  10233. }
  10234. //待双人核对
  10235. if pat_type == 5 {
  10236. for _, item := range monitor {
  10237. if item.DoubleCheck == nil {
  10238. mds = append(mds, item)
  10239. }
  10240. }
  10241. }
  10242. //医嘱未执行
  10243. if pat_type == 6 {
  10244. for _, item := range monitor {
  10245. if len(item.AdviceList) > 0 {
  10246. mds = append(mds, item)
  10247. }
  10248. }
  10249. }
  10250. //患者未签名
  10251. if pat_type == 7 {
  10252. for _, item := range monitor {
  10253. if item.DialysisOrder != nil {
  10254. if item.DialysisOrder.ID > 0 {
  10255. mds = append(mds, item)
  10256. }
  10257. }
  10258. }
  10259. }
  10260. //目标超滤于实际超滤不同
  10261. if pat_type == 8 {
  10262. for _, item := range monitor {
  10263. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  10264. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  10265. mds = append(mds, item)
  10266. }
  10267. }
  10268. }
  10269. }
  10270. //血压少于5次
  10271. if pat_type == 9 {
  10272. for _, item := range monitor {
  10273. if len(item.MonitoringRecord) < 5 {
  10274. mds = append(mds, item)
  10275. }
  10276. }
  10277. }
  10278. if pat_type == 13 {
  10279. for _, item := range monitor {
  10280. if len(item.MonitoringRecord) < 3 {
  10281. mds = append(mds, item)
  10282. }
  10283. }
  10284. }
  10285. if pat_type == 10 {
  10286. for _, item := range monitor {
  10287. if len(item.MonitoringRecord) == 0 {
  10288. mds = append(mds, item)
  10289. }
  10290. }
  10291. }
  10292. if pat_type == 11 {
  10293. for _, item := range monitor {
  10294. if len(item.MonitoringRecord) > 0 {
  10295. mds = append(mds, item)
  10296. }
  10297. }
  10298. }
  10299. if pat_type == 12 {
  10300. for _, item := range monitor {
  10301. if len(item.MonitoringRecord) > 0 {
  10302. mds = append(mds, item)
  10303. }
  10304. }
  10305. }
  10306. if err == nil {
  10307. c.ServeSuccessJSON(map[string]interface{}{
  10308. "monitor": mds,
  10309. "patients": patients,
  10310. })
  10311. } else {
  10312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10313. }
  10314. }
  10315. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  10316. admin_user_id, _ := c.GetInt64("admin_user_id")
  10317. timeStr := time.Now().Format("2006-01-02")
  10318. timeLayout := "2006-01-02 15:04:05"
  10319. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10320. timenow := timeStringToTime.Unix()
  10321. orgId := c.GetMobileAdminUserInfo().Org.Id
  10322. //查询当前护士的患者
  10323. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  10324. var patientIds []int64
  10325. for _, item := range orderList {
  10326. patientIds = append(patientIds, item.PatientId)
  10327. }
  10328. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  10329. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  10330. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  10331. //药品管理信息
  10332. _, drugStockConfig := service.FindHisConfig(orgId)
  10333. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  10334. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  10335. c.ServeSuccessJSON(map[string]interface{}{
  10336. "adviceList": adviceList,
  10337. "hisAdviceList": hisAdviceList,
  10338. "projectList": projectList,
  10339. "drugStockConfig": drugStockConfig,
  10340. "patientList": patientList,
  10341. "projectConfig": projectConfig,
  10342. })
  10343. }
  10344. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  10345. patient_id, _ := c.GetInt64("patient_id")
  10346. org_id := c.GetMobileAdminUserInfo().Org.Id
  10347. recrods, _ := service.GetLastAcceptRecrods(patient_id, org_id)
  10348. c.ServeSuccessJSON(map[string]interface{}{
  10349. "recrods": recrods,
  10350. })
  10351. }
  10352. func (c *DialysisAPIController) ExMobileChangeSch() {
  10353. id_one, _ := c.GetInt64("id_one")
  10354. id_two, _ := c.GetInt64("id_two")
  10355. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10356. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10357. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  10358. //if order2.ID > 0 {
  10359. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  10360. // return
  10361. //}
  10362. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10363. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10364. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10365. if count > 0 {
  10366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10367. return
  10368. }
  10369. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  10370. if count1 > 0 {
  10371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10372. return
  10373. }
  10374. }
  10375. err := service.UpdateScheduleThree(sch, sch_two)
  10376. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10377. if order.ID > 0 {
  10378. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10379. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10380. redis := service.RedisClient()
  10381. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10382. redis.Set(key, "", time.Second)
  10383. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10384. //清空key 值
  10385. redis.Set(keyOne, "", time.Second)
  10386. }
  10387. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10388. if orderOne.ID > 0 {
  10389. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10390. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10391. redis := service.RedisClient()
  10392. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10393. redis.Set(key, "", time.Second)
  10394. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10395. //清空key 值
  10396. redis.Set(keyOne, "", time.Second)
  10397. }
  10398. if err == nil {
  10399. //去除当天患者排班中重复数据,保留最后一条数据
  10400. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10401. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10402. c.ServeSuccessJSON(map[string]interface{}{
  10403. "msg": "交换成功",
  10404. })
  10405. } else {
  10406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10407. return
  10408. }
  10409. }
  10410. func (c *DialysisAPIController) MobileCoverSch() {
  10411. id_one, _ := c.GetInt64("id_one")
  10412. id_two, _ := c.GetInt64("id_two")
  10413. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10414. //针对凤凰医院
  10415. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  10416. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10417. if len(advice) > 0 {
  10418. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10419. }
  10420. }
  10421. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  10422. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10423. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10424. if len(hisAdvice) > 0 {
  10425. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10426. }
  10427. if len(project) > 0 {
  10428. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10429. }
  10430. }
  10431. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10432. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10433. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10434. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10435. if count > 0 {
  10436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10437. return
  10438. }
  10439. }
  10440. var new_sch models.Schedule
  10441. new_sch = sch
  10442. new_sch.BedId = sch_two.BedId
  10443. new_sch.ScheduleDate = sch_two.ScheduleDate
  10444. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10445. new_sch.PartitionId = sch_two.PartitionId
  10446. new_sch.ScheduleType = sch_two.ScheduleType
  10447. new_sch.ID = 0
  10448. //删除原来的排班
  10449. err := service.SaveSchTwo(sch, sch_two)
  10450. //生成新的排班
  10451. if err == nil {
  10452. err2 := service.SaveSch(&new_sch)
  10453. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10454. if order.ID > 0 {
  10455. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10456. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10457. redis := service.RedisClient()
  10458. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10459. redis.Set(key, "", time.Second)
  10460. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10461. //清空key 值
  10462. redis.Set(keyOne, "", time.Second)
  10463. }
  10464. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10465. if orderOne.ID > 0 {
  10466. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10467. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10468. redis := service.RedisClient()
  10469. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10470. redis.Set(key, "", time.Second)
  10471. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10472. //清空key 值
  10473. redis.Set(keyOne, "", time.Second)
  10474. }
  10475. if err2 == nil {
  10476. //去除当天患者排班中重复数据,保留最后一条数据
  10477. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10478. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10479. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10480. c.ServeSuccessJSON(map[string]interface{}{
  10481. "msg": "覆盖成功",
  10482. "new_sch": new_sch,
  10483. })
  10484. } else {
  10485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10486. return
  10487. }
  10488. } else {
  10489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10490. return
  10491. }
  10492. }
  10493. func (c *DialysisAPIController) BatchCheckAdvice() {
  10494. patient_id, _ := c.GetInt64("patient_id")
  10495. advice_date, _ := c.GetInt64("advice_date")
  10496. org_id := c.GetMobileAdminUserInfo().Org.Id
  10497. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10498. //查询是his系统还是血透系统
  10499. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10500. //his客户
  10501. if configs.IsOpen == 1 {
  10502. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10503. for _, item := range adviceList {
  10504. service.BatchCheckHisAdvice(item.ID, creater)
  10505. }
  10506. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10507. for _, item := range projectList {
  10508. service.BatchCheckProject(item.ID, creater)
  10509. }
  10510. c.ServeSuccessJSON(map[string]interface{}{
  10511. "adviceList": adviceList,
  10512. "projectList": projectList,
  10513. })
  10514. }
  10515. if configs.IsOpen != 1 {
  10516. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10517. for _, item := range adviceList {
  10518. service.BatchAdviceList(item.ID, creater)
  10519. }
  10520. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10521. for _, item := range projectList {
  10522. service.BatchCheckProject(item.ID, creater)
  10523. }
  10524. c.ServeSuccessJSON(map[string]interface{}{
  10525. "adviceList": adviceList,
  10526. "projectList": projectList,
  10527. })
  10528. }
  10529. return
  10530. }
  10531. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10532. org_id := c.GetMobileAdminUserInfo().Org.Id
  10533. drugList, _ := service.GetAllDrugList(org_id)
  10534. c.ServeSuccessJSON(map[string]interface{}{
  10535. "drugList": drugList,
  10536. })
  10537. }
  10538. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10539. org_id := c.GetMobileAdminUserInfo().Org.Id
  10540. dataBody := make(map[string]interface{}, 0)
  10541. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10542. if err != nil {
  10543. utils.ErrorLog(err.Error())
  10544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10545. return
  10546. }
  10547. timeLayout := "2006-01-02"
  10548. loc, _ := time.LoadLocation("Local")
  10549. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10550. utils.ErrorLog("advice_type")
  10551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10552. return
  10553. }
  10554. adviceType := int64(dataBody["advice_type"].(float64))
  10555. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10556. utils.ErrorLog("start_time")
  10557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10558. return
  10559. }
  10560. startTime2, _ := dataBody["start_time"].(string)
  10561. time_arr := strings.Split(startTime2, " ")
  10562. if len(time_arr) > 0 {
  10563. startTime2 = time_arr[0]
  10564. }
  10565. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10566. utils.ErrorLog("advice_date")
  10567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10568. return
  10569. }
  10570. advice_date, _ := dataBody["advice_date"].(string)
  10571. var advicedateunix int64
  10572. if len(advice_date) > 0 {
  10573. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10574. if err != nil {
  10575. fmt.Println(err)
  10576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10577. return
  10578. }
  10579. advicedateunix = theTime.Unix()
  10580. }
  10581. adviceDate := startTime2
  10582. if len(adviceDate) == 0 {
  10583. utils.ErrorLog("len(adviceDate) == 0")
  10584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10585. return
  10586. }
  10587. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10588. if err != nil {
  10589. utils.ErrorLog(err.Error())
  10590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10591. return
  10592. }
  10593. AdviceDate := advicedateunix
  10594. RecordDate := advicedateunix
  10595. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10596. utils.ErrorLog("start_time")
  10597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10598. return
  10599. }
  10600. startTime, _ := dataBody["start_time"].(string)
  10601. if len(startTime) == 0 {
  10602. utils.ErrorLog("len(start_time) == 0")
  10603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10604. return
  10605. }
  10606. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10607. if err != nil {
  10608. utils.ErrorLog(err.Error())
  10609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10610. return
  10611. }
  10612. StartTime := theTime.Unix()
  10613. advice_name, _ := dataBody["advice_name"].(string)
  10614. advice_desc, _ := dataBody["advice_desc"].(string)
  10615. delivery_way, _ := dataBody["delivery_way"].(string)
  10616. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10617. frequency_type := int64(dataBody["frequency_type"].(float64))
  10618. frequency_week, _ := dataBody["frequency_week"].(string)
  10619. prescribing_number := dataBody["prescribing_number"].(float64)
  10620. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10621. remark := dataBody["remark"].(string)
  10622. single_dose := dataBody["single_dose"].(float64)
  10623. single_dose_unit := dataBody["single_dose_unit"].(string)
  10624. patient_id := int64(dataBody["patient_id"].(float64))
  10625. day_count := int64(dataBody["day_count"].(float64))
  10626. groupNo := int64(dataBody["group_no"].(float64))
  10627. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10628. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10629. if groupNo <= 0 {
  10630. group := service.GetMaxAdviceGroupID(org_id)
  10631. groupNo = group + 1
  10632. }
  10633. var template_id = ""
  10634. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10635. template_id = "M" + adviceLastId
  10636. advice := models.DoctorAdvice{
  10637. UserOrgId: org_id,
  10638. PatientId: patient_id,
  10639. AdviceType: adviceType,
  10640. AdviceDate: AdviceDate,
  10641. StartTime: StartTime,
  10642. AdviceName: advice_name,
  10643. AdviceDesc: advice_desc,
  10644. ReminderDate: 0,
  10645. SingleDose: single_dose,
  10646. SingleDoseUnit: single_dose_unit,
  10647. DrugSpec: 0,
  10648. DrugSpecUnit: "",
  10649. PrescribingNumber: prescribing_number,
  10650. PrescribingNumberUnit: prescribing_number_unit,
  10651. DeliveryWay: delivery_way,
  10652. ExecutionFrequency: execution_frequency,
  10653. AdviceDoctor: advice_doctor,
  10654. Status: 1,
  10655. CreatedTime: time.Now().Unix(),
  10656. UpdatedTime: 0,
  10657. AdviceAffirm: "",
  10658. Remark: remark,
  10659. StopTime: 0,
  10660. StopReason: "",
  10661. StopDoctor: 0,
  10662. StopState: 2,
  10663. ParentId: 0,
  10664. ExecutionTime: 0,
  10665. ExecutionStaff: 0,
  10666. ExecutionState: 0,
  10667. Checker: 0,
  10668. RecordDate: RecordDate,
  10669. DialysisOrderId: 0,
  10670. CheckTime: 0,
  10671. CheckState: 0,
  10672. AdviceId: 0,
  10673. RemindType: 0,
  10674. FrequencyType: frequency_type,
  10675. DayCount: day_count,
  10676. WeekDay: frequency_week,
  10677. ChildDoctorAdvice: nil,
  10678. TemplateId: template_id,
  10679. Modifier: 0,
  10680. IsCheck: 0,
  10681. Way: 0,
  10682. DrugId: 0,
  10683. DrugNameId: 0,
  10684. IsMedicine: 0,
  10685. PushStartTime: 0,
  10686. IsSettle: 0,
  10687. IsPrescription: 0,
  10688. GroupNo: groupNo,
  10689. }
  10690. service.CreateMobileAdivce(advice)
  10691. c.ServeSuccessJSON(map[string]interface{}{
  10692. "msg": "保存成功!",
  10693. })
  10694. }
  10695. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10696. patient_id, _ := c.GetInt64("patient_id")
  10697. org_id := c.GetMobileAdminUserInfo().Org.Id
  10698. app_id := c.GetMobileAdminUserInfo().App.Id
  10699. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10700. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10701. c.ServeSuccessJSON(map[string]interface{}{
  10702. "adviceList": adviceList,
  10703. "adminRoles": adminRoles,
  10704. })
  10705. }
  10706. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10707. org_id := c.GetMobileAdminUserInfo().Org.Id
  10708. dataBody := make(map[string]interface{}, 0)
  10709. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10710. if err != nil {
  10711. utils.ErrorLog(err.Error())
  10712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10713. return
  10714. }
  10715. timeLayout := "2006-01-02"
  10716. loc, _ := time.LoadLocation("Local")
  10717. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10718. utils.ErrorLog("start_time")
  10719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10720. return
  10721. }
  10722. startTime2, _ := dataBody["start_time"].(string)
  10723. time_arr := strings.Split(startTime2, " ")
  10724. if len(time_arr) > 0 {
  10725. startTime2 = time_arr[0]
  10726. }
  10727. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10728. utils.ErrorLog("advice_date")
  10729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10730. return
  10731. }
  10732. advice_date, _ := dataBody["advice_date"].(string)
  10733. var advicedateunix int64
  10734. if len(advice_date) > 0 {
  10735. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10736. if err != nil {
  10737. fmt.Println(err)
  10738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10739. return
  10740. }
  10741. advicedateunix = theTime.Unix()
  10742. }
  10743. adviceDate := startTime2
  10744. if len(adviceDate) == 0 {
  10745. utils.ErrorLog("len(adviceDate) == 0")
  10746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10747. return
  10748. }
  10749. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10750. if err != nil {
  10751. utils.ErrorLog(err.Error())
  10752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10753. return
  10754. }
  10755. AdviceDate := advicedateunix
  10756. RecordDate := advicedateunix
  10757. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10758. utils.ErrorLog("start_time")
  10759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10760. return
  10761. }
  10762. startTime, _ := dataBody["start_time"].(string)
  10763. if len(startTime) == 0 {
  10764. utils.ErrorLog("len(start_time) == 0")
  10765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10766. return
  10767. }
  10768. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10769. if err != nil {
  10770. utils.ErrorLog(err.Error())
  10771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10772. return
  10773. }
  10774. StartTime := theTime.Unix()
  10775. advice_name, _ := dataBody["advice_name"].(string)
  10776. advice_desc, _ := dataBody["advice_desc"].(string)
  10777. delivery_way, _ := dataBody["delivery_way"].(string)
  10778. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10779. prescribing_number := dataBody["prescribing_number"].(float64)
  10780. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10781. remark := dataBody["remark"].(string)
  10782. single_dose := dataBody["single_dose"].(float64)
  10783. single_dose_unit := dataBody["single_dose_unit"].(string)
  10784. patient_id := int64(dataBody["patient_id"].(float64))
  10785. groupNo := int64(dataBody["group_no"].(float64))
  10786. parent_id := int64(dataBody["parent_id"].(float64))
  10787. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10788. advice := models.XtDoctorAdviceOne{
  10789. UserOrgId: org_id,
  10790. PatientId: patient_id,
  10791. AdviceType: 1,
  10792. AdviceDate: AdviceDate,
  10793. StartTime: StartTime,
  10794. AdviceName: advice_name,
  10795. AdviceDesc: advice_desc,
  10796. ReminderDate: 0,
  10797. SingleDose: single_dose,
  10798. SingleDoseUnit: single_dose_unit,
  10799. PrescribingNumber: prescribing_number,
  10800. PrescribingNumberUnit: prescribing_number_unit,
  10801. DeliveryWay: delivery_way,
  10802. ExecutionFrequency: execution_frequency,
  10803. AdviceDoctor: advice_doctor,
  10804. Status: 1,
  10805. CreatedTime: time.Now().Unix(),
  10806. UpdatedTime: time.Now().Unix(),
  10807. AdviceAffirm: "",
  10808. Remark: remark,
  10809. StopTime: 0,
  10810. StopReason: "",
  10811. StopDoctor: 0,
  10812. StopState: 2,
  10813. ParentId: parent_id,
  10814. ExecutionTime: 0,
  10815. ExecutionStaff: 0,
  10816. ExecutionState: 0,
  10817. Checker: 0,
  10818. RecordDate: RecordDate,
  10819. DialysisOrderId: 0,
  10820. CheckTime: 0,
  10821. CheckState: 0,
  10822. DrugSpec: 0,
  10823. DrugSpecUnit: "",
  10824. Groupno: groupNo,
  10825. RemindType: 0,
  10826. FrequencyType: 0,
  10827. DayCount: 0,
  10828. WeekDay: "",
  10829. TemplateId: "",
  10830. Modifier: 0,
  10831. }
  10832. service.CreateMobileAdivceOne(advice)
  10833. c.ServeSuccessJSON(map[string]interface{}{
  10834. "msg": "保存成功!",
  10835. })
  10836. }
  10837. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10838. id, _ := c.GetInt64("id")
  10839. service.DeleteSelfAdviceSubAdvice(id)
  10840. c.ServeSuccessJSON(map[string]interface{}{
  10841. "msg": "保存成功!",
  10842. })
  10843. }
  10844. func (c *DialysisAPIController) GetEditAdviceAction() {
  10845. id, _ := c.GetInt64("id")
  10846. org_id := c.GetMobileAdminUserInfo().Org.Id
  10847. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10848. drugList, _ := service.GetAllDrugList(org_id)
  10849. c.ServeSuccessJSON(map[string]interface{}{
  10850. "advice": advice,
  10851. "drugList": drugList,
  10852. })
  10853. }
  10854. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10855. dataBody := make(map[string]interface{}, 0)
  10856. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10857. if err != nil {
  10858. utils.ErrorLog(err.Error())
  10859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10860. return
  10861. }
  10862. timeLayout := "2006-01-02"
  10863. loc, _ := time.LoadLocation("Local")
  10864. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10865. utils.ErrorLog("start_time")
  10866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10867. return
  10868. }
  10869. startTime2, _ := dataBody["start_time"].(string)
  10870. time_arr := strings.Split(startTime2, " ")
  10871. if len(time_arr) > 0 {
  10872. startTime2 = time_arr[0]
  10873. }
  10874. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10875. utils.ErrorLog("advice_date")
  10876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10877. return
  10878. }
  10879. advice_date, _ := dataBody["advice_date"].(string)
  10880. var advicedateunix int64
  10881. if len(advice_date) > 0 {
  10882. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10883. if err != nil {
  10884. fmt.Println(err)
  10885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10886. return
  10887. }
  10888. advicedateunix = theTime.Unix()
  10889. }
  10890. adviceDate := startTime2
  10891. if len(adviceDate) == 0 {
  10892. utils.ErrorLog("len(adviceDate) == 0")
  10893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10894. return
  10895. }
  10896. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10897. if err != nil {
  10898. utils.ErrorLog(err.Error())
  10899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10900. return
  10901. }
  10902. AdviceDate := advicedateunix
  10903. RecordDate := advicedateunix
  10904. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10905. utils.ErrorLog("start_time")
  10906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10907. return
  10908. }
  10909. startTime, _ := dataBody["start_time"].(string)
  10910. if len(startTime) == 0 {
  10911. utils.ErrorLog("len(start_time) == 0")
  10912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10913. return
  10914. }
  10915. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10916. if err != nil {
  10917. utils.ErrorLog(err.Error())
  10918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10919. return
  10920. }
  10921. StartTime := theTime.Unix()
  10922. advice_name, _ := dataBody["advice_name"].(string)
  10923. advice_desc, _ := dataBody["advice_desc"].(string)
  10924. delivery_way, _ := dataBody["delivery_way"].(string)
  10925. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10926. prescribing_number := dataBody["prescribing_number"].(float64)
  10927. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10928. remark := dataBody["remark"].(string)
  10929. single_dose := dataBody["single_dose"].(float64)
  10930. single_dose_unit := dataBody["single_dose_unit"].(string)
  10931. id := int64(dataBody["id"].(float64))
  10932. frequency_type := int64(dataBody["frequency_type"].(float64))
  10933. frequency_week, _ := dataBody["frequency_week"].(string)
  10934. day_count := int64(dataBody["day_count"].(float64))
  10935. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10936. advice := models.XtDoctorAdviceOne{
  10937. AdviceDate: AdviceDate,
  10938. StartTime: StartTime,
  10939. AdviceName: advice_name,
  10940. AdviceDesc: advice_desc,
  10941. SingleDose: single_dose,
  10942. SingleDoseUnit: single_dose_unit,
  10943. PrescribingNumber: prescribing_number,
  10944. PrescribingNumberUnit: prescribing_number_unit,
  10945. DeliveryWay: delivery_way,
  10946. ExecutionFrequency: execution_frequency,
  10947. AdviceDoctor: advice_doctor,
  10948. Remark: remark,
  10949. RecordDate: RecordDate,
  10950. FrequencyType: frequency_type,
  10951. DayCount: day_count,
  10952. WeekDay: frequency_week,
  10953. }
  10954. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10955. c.ServeSuccessJSON(map[string]interface{}{
  10956. "advice": advice,
  10957. })
  10958. }
  10959. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10960. dataBody := make(map[string]interface{}, 0)
  10961. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10962. if err != nil {
  10963. utils.ErrorLog(err.Error())
  10964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10965. return
  10966. }
  10967. timeLayout := "2006-01-02"
  10968. loc, _ := time.LoadLocation("Local")
  10969. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10970. utils.ErrorLog("start_time")
  10971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10972. return
  10973. }
  10974. startTime2, _ := dataBody["start_time"].(string)
  10975. time_arr := strings.Split(startTime2, " ")
  10976. if len(time_arr) > 0 {
  10977. startTime2 = time_arr[0]
  10978. }
  10979. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10980. utils.ErrorLog("advice_date")
  10981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10982. return
  10983. }
  10984. advice_date, _ := dataBody["advice_date"].(string)
  10985. var advicedateunix int64
  10986. if len(advice_date) > 0 {
  10987. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10988. if err != nil {
  10989. fmt.Println(err)
  10990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10991. return
  10992. }
  10993. advicedateunix = theTime.Unix()
  10994. }
  10995. adviceDate := startTime2
  10996. if len(adviceDate) == 0 {
  10997. utils.ErrorLog("len(adviceDate) == 0")
  10998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10999. return
  11000. }
  11001. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11002. if err != nil {
  11003. utils.ErrorLog(err.Error())
  11004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11005. return
  11006. }
  11007. AdviceDate := advicedateunix
  11008. RecordDate := advicedateunix
  11009. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11010. utils.ErrorLog("start_time")
  11011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11012. return
  11013. }
  11014. startTime, _ := dataBody["start_time"].(string)
  11015. if len(startTime) == 0 {
  11016. utils.ErrorLog("len(start_time) == 0")
  11017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11018. return
  11019. }
  11020. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11021. if err != nil {
  11022. utils.ErrorLog(err.Error())
  11023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11024. return
  11025. }
  11026. StartTime := theTime.Unix()
  11027. advice_name, _ := dataBody["advice_name"].(string)
  11028. advice_desc, _ := dataBody["advice_desc"].(string)
  11029. delivery_way, _ := dataBody["delivery_way"].(string)
  11030. execution_frequency, _ := dataBody["execution_frequency"].(string)
  11031. prescribing_number := dataBody["prescribing_number"].(float64)
  11032. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  11033. remark := dataBody["remark"].(string)
  11034. single_dose := dataBody["single_dose"].(float64)
  11035. single_dose_unit := dataBody["single_dose_unit"].(string)
  11036. id := int64(dataBody["id"].(float64))
  11037. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11038. advice := models.XtDoctorAdviceOne{
  11039. AdviceDate: AdviceDate,
  11040. StartTime: StartTime,
  11041. AdviceName: advice_name,
  11042. AdviceDesc: advice_desc,
  11043. SingleDose: single_dose,
  11044. SingleDoseUnit: single_dose_unit,
  11045. PrescribingNumber: prescribing_number,
  11046. PrescribingNumberUnit: prescribing_number_unit,
  11047. DeliveryWay: delivery_way,
  11048. ExecutionFrequency: execution_frequency,
  11049. AdviceDoctor: advice_doctor,
  11050. Remark: remark,
  11051. RecordDate: RecordDate,
  11052. }
  11053. service.UpdateMobileDoctorAdviceById(id, advice)
  11054. c.ServeSuccessJSON(map[string]interface{}{
  11055. "advice": advice,
  11056. })
  11057. }
  11058. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  11059. dataBody := make(map[string]interface{}, 0)
  11060. timeLayout := "2006-01-02"
  11061. loc, _ := time.LoadLocation("Local")
  11062. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11063. if err != nil {
  11064. utils.ErrorLog(err.Error())
  11065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11066. return
  11067. }
  11068. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11069. utils.ErrorLog("start_time")
  11070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11071. return
  11072. }
  11073. startTime2, _ := dataBody["start_time"].(string)
  11074. time_arr := strings.Split(startTime2, " ")
  11075. if len(time_arr) > 0 {
  11076. startTime2 = time_arr[0]
  11077. }
  11078. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  11079. utils.ErrorLog("advice_date")
  11080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11081. return
  11082. }
  11083. advice_date, _ := dataBody["advice_date"].(string)
  11084. var advicedateunix int64
  11085. if len(advice_date) > 0 {
  11086. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  11087. if err != nil {
  11088. fmt.Println(err)
  11089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11090. return
  11091. }
  11092. advicedateunix = theTime.Unix()
  11093. }
  11094. adviceDate := startTime2
  11095. if len(adviceDate) == 0 {
  11096. utils.ErrorLog("len(adviceDate) == 0")
  11097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11098. return
  11099. }
  11100. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11101. if err != nil {
  11102. utils.ErrorLog(err.Error())
  11103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11104. return
  11105. }
  11106. RecordDate := advicedateunix
  11107. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11108. utils.ErrorLog("start_time")
  11109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11110. return
  11111. }
  11112. startTime, _ := dataBody["start_time"].(string)
  11113. if len(startTime) == 0 {
  11114. utils.ErrorLog("len(start_time) == 0")
  11115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11116. return
  11117. }
  11118. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11119. if err != nil {
  11120. utils.ErrorLog(err.Error())
  11121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11122. return
  11123. }
  11124. StartTime := theTime.Unix()
  11125. patient_id := int64(dataBody["patient_id"].(float64))
  11126. group_no := int64(dataBody["group_no"].(float64))
  11127. org_id := c.GetMobileAdminUserInfo().Org.Id
  11128. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11129. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  11130. utils.ErrorLog("advices")
  11131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11132. return
  11133. }
  11134. adviceNames := dataBody["advices"].([]interface{})
  11135. var advices []*models.GroupAdvice
  11136. for _, adviceNameMap := range adviceNames {
  11137. var advice models.GroupAdvice
  11138. adviceNameM := adviceNameMap.(map[string]interface{})
  11139. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  11140. utils.ErrorLog("advice_name")
  11141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11142. return
  11143. }
  11144. adviceName, _ := adviceNameM["advice_name"].(string)
  11145. if len(adviceName) == 0 {
  11146. utils.ErrorLog("len(advice_name) == 0")
  11147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11148. return
  11149. }
  11150. advice.AdviceName = adviceName
  11151. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  11152. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  11153. advice.DrugSpec = drugSpec
  11154. }
  11155. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  11156. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  11157. advice.AdviceDesc = adviceDesc
  11158. }
  11159. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  11160. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  11161. advice.DrugSpecUnit = drugSpecUnit
  11162. }
  11163. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  11164. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  11165. advice.SingleDose = singleDose
  11166. }
  11167. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  11168. singleDose := adviceNameM["single_dose"].(float64)
  11169. advice.SingleDose = singleDose
  11170. }
  11171. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  11172. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  11173. advice.SingleDoseUnit = singleDoseUnit
  11174. }
  11175. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  11176. tmp := adviceNameM["single_dose_unit"].(float64)
  11177. singleDoseUnit := service.TypeConversion(tmp)
  11178. advice.SingleDoseUnit = singleDoseUnit
  11179. }
  11180. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  11181. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  11182. advice.PrescribingNumber = prescribingNumber
  11183. }
  11184. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  11185. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  11186. advice.PrescribingNumber = prescribingNumber
  11187. }
  11188. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  11189. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  11190. advice.PrescribingNumberUnit = prescribingNumberUnit
  11191. }
  11192. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  11193. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  11194. advice.DeliveryWay = deliveryWay
  11195. }
  11196. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  11197. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  11198. advice.ExecutionFrequency = executionFrequency
  11199. }
  11200. remark, _ := adviceNameM["remark"].(string)
  11201. advice.Remark = remark
  11202. advice.AdviceType = 1
  11203. advice.StartTime = StartTime
  11204. advice.RecordDate = RecordDate
  11205. advice.PatientId = patient_id
  11206. advice.UserOrgId = org_id
  11207. advice.AdviceDoctor = advice_doctor
  11208. advice.StopState = 2
  11209. advices = append(advices, &advice)
  11210. }
  11211. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  11212. c.ServeSuccessJSON(map[string]interface{}{
  11213. "advice": newAdvices,
  11214. })
  11215. }
  11216. func (c *DialysisAPIController) StopLongAdvice() {
  11217. stop_time := c.GetString("execution_time")
  11218. id, _ := c.GetInt64("id")
  11219. if len(stop_time) <= 0 {
  11220. utils.ErrorLog("stop_time")
  11221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11222. return
  11223. }
  11224. timeLayout2 := "2006-01-02 15:04:05"
  11225. loc, _ := time.LoadLocation("Local")
  11226. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  11227. if errs != nil {
  11228. utils.ErrorLog(errs.Error())
  11229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11230. return
  11231. }
  11232. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  11233. c.ServeSuccessJSON(map[string]interface{}{
  11234. "advice": advice,
  11235. })
  11236. }
  11237. func (c *DialysisAPIController) BatchAdviceCheckList() {
  11238. dataBody := make(map[string]interface{}, 0)
  11239. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11240. if err != nil {
  11241. utils.ErrorLog(err.Error())
  11242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11243. return
  11244. }
  11245. orgId := c.GetMobileAdminUserInfo().Org.Id
  11246. patient_id := int64(dataBody["patient_id"].(float64))
  11247. record_date := int64(dataBody["record_date"].(float64))
  11248. checker := int64(dataBody["checker"].(float64))
  11249. check_time := dataBody["check_time"].(string)
  11250. checkTime, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", check_time)
  11251. if parseStartDateErr != nil {
  11252. c.ErrorLog("时间解析失败:%v", parseStartDateErr)
  11253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11254. return
  11255. }
  11256. var advice_id []int64
  11257. var his_advice_id []int64
  11258. var project_id []int64
  11259. var team_list []int64
  11260. if dataBody["new_advice_list"] != nil && reflect.TypeOf(dataBody["new_advice_list"]).String() == "[]interface {}" {
  11261. newAdviceList, _ := dataBody["new_advice_list"].([]interface{})
  11262. if len(newAdviceList) > 0 {
  11263. for _, item := range newAdviceList {
  11264. items := item.(map[string]interface{})
  11265. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11266. utils.ErrorLog("id")
  11267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11268. return
  11269. }
  11270. id := int64(items["id"].(float64))
  11271. if items["origin"] == nil || reflect.TypeOf(items["origin"]).String() != "float64" {
  11272. utils.ErrorLog("origin")
  11273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11274. return
  11275. }
  11276. origin := int64(items["origin"].(float64))
  11277. if items["team_id"] == nil || reflect.TypeOf(items["team_id"]).String() != "float64" {
  11278. utils.ErrorLog("team_id")
  11279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11280. return
  11281. }
  11282. team_id := int64(items["team_id"].(float64))
  11283. if team_id == 0 {
  11284. //临时医嘱
  11285. if origin == 1 {
  11286. service.BatchAdviceDoctorList(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11287. advice_id = append(advice_id, id)
  11288. }
  11289. //his医嘱
  11290. if origin == 2 {
  11291. service.BatchHisAdviceDoctorList(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11292. his_advice_id = append(his_advice_id, id)
  11293. }
  11294. //his医嘱
  11295. if origin == 3 {
  11296. service.BatchHisPrescriptionProject(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11297. project_id = append(project_id, id)
  11298. }
  11299. }
  11300. if team_id > 0 {
  11301. service.BatchCheckPrescriptionProject(patient_id, record_date, team_id, orgId, checker, checkTime.Unix())
  11302. team_list = append(team_list, team_id)
  11303. }
  11304. }
  11305. }
  11306. }
  11307. advice, _ := service.GetBatchAdviceList(advice_id)
  11308. hisadvice, _ := service.GetBatchHisAdviceList(his_advice_id)
  11309. hisproject, _ := service.GetBatchPrescriptionList(project_id)
  11310. teamlist, _ := service.GetBatchTeamList(team_list, patient_id, record_date, orgId)
  11311. c.ServeSuccessJSON(map[string]interface{}{
  11312. "advice": advice,
  11313. "hisadvice": hisadvice,
  11314. "hisproject": hisproject,
  11315. "teamlist": teamlist,
  11316. })
  11317. return
  11318. }
  11319. func (c *DialysisAPIController) BatchAdviceExeCutionList() {
  11320. dataBody := make(map[string]interface{}, 0)
  11321. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11322. if err != nil {
  11323. utils.ErrorLog(err.Error())
  11324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11325. return
  11326. }
  11327. orgId := c.GetMobileAdminUserInfo().Org.Id
  11328. patient_id := int64(dataBody["patient_id"].(float64))
  11329. record_date := int64(dataBody["record_date"].(float64))
  11330. execution_staff := int64(dataBody["execution_staff"].(float64))
  11331. execution_time := dataBody["execution_time"].(string)
  11332. executionTime, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  11333. if parseStartDateErr != nil {
  11334. c.ErrorLog("时间解析失败:%v", parseStartDateErr)
  11335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11336. return
  11337. }
  11338. var advice_id []int64
  11339. var his_advice_id []int64
  11340. var project_id []int64
  11341. var team_list []int64
  11342. if dataBody["new_advice_list"] != nil && reflect.TypeOf(dataBody["new_advice_list"]).String() == "[]interface {}" {
  11343. newAdviceList, _ := dataBody["new_advice_list"].([]interface{})
  11344. if len(newAdviceList) > 0 {
  11345. for _, item := range newAdviceList {
  11346. items := item.(map[string]interface{})
  11347. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11348. utils.ErrorLog("id")
  11349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11350. return
  11351. }
  11352. id := int64(items["id"].(float64))
  11353. if items["origin"] == nil || reflect.TypeOf(items["origin"]).String() != "float64" {
  11354. utils.ErrorLog("origin")
  11355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11356. return
  11357. }
  11358. origin := int64(items["origin"].(float64))
  11359. if items["team_id"] == nil || reflect.TypeOf(items["team_id"]).String() != "float64" {
  11360. utils.ErrorLog("team_id")
  11361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11362. return
  11363. }
  11364. team_id := int64(items["team_id"].(float64))
  11365. if team_id == 0 {
  11366. //临时医嘱
  11367. if origin == 1 {
  11368. service.BatchExecutionAdviceDoctorList(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11369. advice_id = append(advice_id, id)
  11370. }
  11371. //his医嘱
  11372. if origin == 2 {
  11373. service.BatchExecutionHisAdviceDoctorList(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11374. his_advice_id = append(his_advice_id, id)
  11375. }
  11376. //his医嘱
  11377. if origin == 3 {
  11378. service.BatchExecutionHisPrescriptionProject(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11379. project_id = append(project_id, id)
  11380. }
  11381. }
  11382. if team_id > 0 {
  11383. service.BatchExecutionPrescriptionProject(patient_id, record_date, team_id, orgId, execution_staff, executionTime.Unix())
  11384. team_list = append(team_list, team_id)
  11385. }
  11386. }
  11387. }
  11388. }
  11389. advice, _ := service.GetBatchAdviceList(advice_id)
  11390. hisadvice, _ := service.GetBatchHisAdviceList(his_advice_id)
  11391. hisproject, _ := service.GetBatchPrescriptionList(project_id)
  11392. teamlist, _ := service.GetBatchTeamList(team_list, patient_id, record_date, orgId)
  11393. c.ServeSuccessJSON(map[string]interface{}{
  11394. "advice": advice,
  11395. "hisadvice": hisadvice,
  11396. "hisproject": hisproject,
  11397. "teamlist": teamlist,
  11398. })
  11399. return
  11400. }