dialysis_api_controller.go 313KB

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