dialysis_api_controller.go 373KB

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