dialysis_api_controller.go 374KB

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