dialysis_api_controller.go 310KB

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