dialysis_api_controller.go 447KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var projectsOne []*models.HisPrescriptionProject
  342. var stockType []*models.GoodsTypeOne
  343. var prepare []*models.XtDialysisBeforePrepare
  344. var lastAssessment models.XtPatientVascularAccess
  345. var lastDryWeightDislysis *models.SgjPatientDryweight
  346. var gobalConfig models.GobalConfig
  347. var operators []*models.SgjUserAdminRoles
  348. // 先走redis,没有走数据库
  349. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  350. go func() {
  351. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  352. ch <- struct{}{}
  353. }()
  354. go func() {
  355. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  356. ch <- struct{}{}
  357. }()
  358. go func() {
  359. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  360. ch <- struct{}{}
  361. }()
  362. go func() {
  363. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  364. ch <- struct{}{}
  365. }()
  366. go func() {
  367. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  368. ch <- struct{}{}
  369. }()
  370. go func() {
  371. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  372. ch <- struct{}{}
  373. }()
  374. go func() {
  375. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. ch <- struct{}{}
  377. }()
  378. go func() {
  379. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  380. ch <- struct{}{}
  381. }()
  382. go func() {
  383. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  384. ch <- struct{}{}
  385. }()
  386. go func() {
  387. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  388. ch <- struct{}{}
  389. }()
  390. go func() {
  391. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  392. ch <- struct{}{}
  393. }()
  394. go func() {
  395. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  396. ch <- struct{}{}
  397. }()
  398. go func() {
  399. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  408. ch <- struct{}{}
  409. }()
  410. go func() {
  411. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // 先走redis,没有走数据库
  421. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  422. ch <- struct{}{}
  423. }()
  424. go func() {
  425. // // 先走redis,没有走数据库
  426. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  427. ch <- struct{}{}
  428. }()
  429. go func() {
  430. // 先走redis,没有走数据库
  431. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  432. ch <- struct{}{}
  433. }()
  434. go func() {
  435. // //获取最后一次血管通路
  436. // 先走redis,没有走数据库
  437. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  438. ch <- struct{}{}
  439. }()
  440. go func() {
  441. // 先走redis,没有走数据库
  442. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  443. ch <- struct{}{}
  444. }()
  445. go func() {
  446. // 先走redis,没有走数据库
  447. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  448. ch <- struct{}{}
  449. }()
  450. go func() {
  451. // 先走redis,没有走数据库
  452. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  453. ch <- struct{}{}
  454. }()
  455. for range ch {
  456. // 每次从ch中接收数据,表明一个活动的协程结束
  457. count--
  458. // 当所有活动的协程都结束时,关闭管道
  459. if count == 0 {
  460. close(ch)
  461. }
  462. }
  463. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  464. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  465. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  466. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  468. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  469. var team_projects []*models.HisPrescriptionProject
  470. //var index int64 = 0
  471. for _, item := range temp_team_projects {
  472. //组套里面非检验项目的
  473. if item.HisProject.CostClassify != 3 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 {
  478. team_projects = append(team_projects, item)
  479. }
  480. }
  481. //针对茂名舒和
  482. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  483. if len(projects) > 0 {
  484. for _, item := range projects {
  485. if item.Type == 2 {
  486. if item.HisProject.IsShow == 1 {
  487. projectsOne = append(projectsOne, item)
  488. }
  489. }
  490. if item.Type == 3 {
  491. if item.GoodInfo.IsShow == 1 {
  492. projectsOne = append(projectsOne, item)
  493. }
  494. }
  495. }
  496. }
  497. } else {
  498. for _, item := range projects {
  499. projectsOne = append(projectsOne, item)
  500. }
  501. }
  502. team_projects = RemoveRepeatedCheckRecod(team_projects)
  503. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  504. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  505. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  506. var his_advices []*models.HisDoctorAdviceInfo
  507. var his_advices_one []*models.HisDoctorAdviceInfo
  508. if is_open_config.IsOpen == 1 {
  509. // 先走redis,没有走数据库
  510. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  511. }
  512. //针对茂名舒和
  513. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  514. if len(his_advices) > 0 {
  515. for _, item := range his_advices {
  516. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  517. if drug.IsShow == 1 {
  518. his_advices_one = append(his_advices_one, item)
  519. }
  520. }
  521. }
  522. } else {
  523. if len(his_advices) > 0 {
  524. for _, item := range his_advices {
  525. his_advices_one = append(his_advices_one, item)
  526. }
  527. }
  528. }
  529. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  530. if is_advice_open.IsAdviceOpen == 1 {
  531. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  532. }
  533. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  534. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  535. var remind_lists []models.XtCheckRemind
  536. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  537. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  538. }
  539. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  540. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  541. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  542. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  543. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  544. returnData := map[string]interface{}{
  545. "patient": patient,
  546. "schedual": schedual,
  547. "prescription": dialysisPrescribe,
  548. "solution": dialysisSolution,
  549. "last_prescription": lastDialysisPrescribe,
  550. "receiver_treatment_access": receiverTreatmentAccess,
  551. "predialysis_evaluation": predialysisEvaluation,
  552. "doctor_advices": doctorAdvices,
  553. "double_check": doubleCheck,
  554. "assessment_after_dislysis": assessmentAfterDislysis,
  555. "treatment_summary": treatmentSummary,
  556. "monitor_records": monitorRecords,
  557. "dialysis_order": dialysisOrder,
  558. "operators": operators,
  559. "last_predialysis_evaluation": lastPredialysisEvaluation,
  560. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  561. "last_monitor_record": lastMonitorRecord,
  562. "config": gobalConfig,
  563. "dry_weight": lastDryWeightDislysis,
  564. "system_prescription": systemDialysisPrescribe,
  565. "his_advices": his_advices_one,
  566. "is_open_config": is_open_config,
  567. "stockType": stockType,
  568. "prepare": prepare,
  569. "lastAssessment": lastAssessment,
  570. "prescribeOne": prescribeOne,
  571. "is_project_open_config": is_project_open_config,
  572. "project": projectsOne,
  573. "team_projects": team_projects,
  574. "is_advice_open": is_advice_open,
  575. "prescription_open": prescriptionConfig.IsOpen,
  576. "lastOrder": lastOrder,
  577. "remind_lists": remind_lists,
  578. "lastDialysisPrescription": lastDialysisPrescription,
  579. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  580. "dryWeightList": dryWeightList,
  581. "firstMonitor": firstMonitor,
  582. "lastMonitor": lastMonitor,
  583. }
  584. this.ServeSuccessJSON(returnData)
  585. }
  586. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  587. adminInfo := c.GetMobileAdminUserInfo()
  588. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  589. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  590. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  591. returnData := map[string]interface{}{
  592. "admin_users": adminUsers,
  593. "devices": devices,
  594. "device_numbers": device_numbers,
  595. }
  596. c.ServeSuccessJSON(returnData)
  597. }
  598. func (c *DialysisAPIController) PostAtreatmentInfo() {
  599. id, _ := c.GetInt64("patient", 0)
  600. recordDateStr := c.GetString("record_date")
  601. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  602. summaryContent := c.GetString("summaryContent")
  603. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  604. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  605. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  606. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  607. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  608. nursingRecord := c.GetString("nursing_record")
  609. fmt.Println("护理记录", nursingRecord)
  610. specialRecord := c.GetString("special_record")
  611. fmt.Println("特殊记录", specialRecord)
  612. adminUserInfo := c.GetMobileAdminUserInfo()
  613. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  614. checkStaffId = adminUserInfo.AdminUser.Id
  615. deboardNurseId = adminUserInfo.AdminUser.Id
  616. treatDoctor = adminUserInfo.AdminUser.Id
  617. if id <= 0 {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  622. if patient.ID == 0 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  624. return
  625. }
  626. if len(recordDateStr) == 0 {
  627. recordDateStr = time.Now().Format("2006-01-02")
  628. }
  629. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  630. if parseDateErr != nil {
  631. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. summary := models.TreatmentSummary{
  636. UserOrgId: adminUserInfo.Org.Id,
  637. PatientId: id,
  638. AssessmentDate: recordDate.Unix(),
  639. Mission: propagandaAndEducationContent,
  640. DialysisSummary: summaryContent,
  641. SjNurse: changeMedicalNurseId,
  642. ZlNurse: treatNurseId,
  643. HdNurse: checkStaffId,
  644. XjNurse: deboardNurseId,
  645. ZlDoctor: treatDoctor,
  646. CreatedTime: time.Now().Unix(),
  647. Status: 1,
  648. NursingRecord: nursingRecord,
  649. SpecialRecord: specialRecord,
  650. }
  651. // 查询信息规挡的设置天数
  652. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  653. if infor.ID > 0 && infor.WeekDay > 0 {
  654. var cha_time int64
  655. timeNowStr := time.Now().Format("2006-01-02")
  656. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  657. //今日的日期减去设置的日期
  658. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  659. if cha_time >= recordDate.Unix() {
  660. //查询审核是否允许
  661. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  662. //申请状态不允许的情况 拒绝修改
  663. if infor.ApplicationStatus != 1 {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  665. return
  666. }
  667. }
  668. }
  669. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if treatmentSummary.ID == 0 { //新增
  671. summary.Creater = adminUserInfo.AdminUser.Id
  672. service.AddSigleSummaryRecord(&summary)
  673. finish := models.XtDialysisFinish{
  674. IsFinish: 1,
  675. UserOrgId: adminUserInfo.Org.Id,
  676. Status: 1,
  677. Ctime: time.Now().Unix(),
  678. Mtime: 0,
  679. Module: 10,
  680. RecordDate: recordDate.Unix(),
  681. Sourse: 1,
  682. PatientId: id,
  683. }
  684. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  685. if dialysisFinish.ID == 0 {
  686. service.CreateDialysisFinish(finish)
  687. }
  688. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  689. redis := service.RedisClient()
  690. //清空key 值
  691. redis.Set(key, "", time.Second)
  692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  693. redis.Set(keyOne, "", time.Second)
  694. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  695. redis.Set(keyThree, "", time.Second)
  696. defer redis.Close()
  697. c.ServeSuccessJSON(map[string]interface{}{
  698. "summary": summary,
  699. })
  700. } else { //修改
  701. summary.Creater = treatmentSummary.Creater
  702. summary.CreatedTime = treatmentSummary.CreatedTime
  703. summary.Modifier = adminUserInfo.AdminUser.Id
  704. summary.ID = treatmentSummary.ID
  705. service.UpdateSummeRecord(&summary)
  706. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  707. redis := service.RedisClient()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  711. redis.Set(keyOne, "", time.Second)
  712. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  713. redis.Set(keyThree, "", time.Second)
  714. defer redis.Close()
  715. c.ServeSuccessJSON(map[string]interface{}{
  716. "summary": summary,
  717. })
  718. }
  719. }
  720. func (c *DialysisAPIController) PostDoubleCheck() {
  721. id, _ := c.GetInt64("patient", 0)
  722. recordDateStr := c.GetString("record_date")
  723. checkTimeStr := c.GetString("check_time")
  724. firstCheckTimeStr := c.GetString("first_check_time")
  725. creater, _ := c.GetInt64("creater", 0)
  726. modifier, _ := c.GetInt64("modifier", 0)
  727. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  728. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  729. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  730. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  731. dialysis_item_desc := c.GetString("dialysis_item_desc")
  732. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  733. vascular_access_desc := c.GetString("vascular_access_desc")
  734. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  735. collator, _ := c.GetInt64("collator", 0)
  736. employee_number := c.GetString("employee_number")
  737. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  738. needle_batch_number := c.GetString("needle_batch_number")
  739. if id <= 0 {
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. adminUserInfo := c.GetMobileAdminUserInfo()
  744. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  745. if patient.ID == 0 {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  747. return
  748. }
  749. if len(recordDateStr) == 0 {
  750. recordDateStr = time.Now().Format("2006-01-02")
  751. }
  752. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  753. if parseDateErr != nil {
  754. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  756. return
  757. }
  758. var checkDate int64
  759. if len(checkTimeStr) == 0 {
  760. checkDate = 0
  761. } else {
  762. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  763. checkDate = checkDateUnix.Unix()
  764. }
  765. var firstCheckDate int64
  766. if len(firstCheckTimeStr) == 0 {
  767. firstCheckDate = 0
  768. } else {
  769. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  770. firstCheckDate = firstCheckDateUnix.Unix()
  771. }
  772. if adminUserInfo.Org.Id == 10644 {
  773. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 {
  776. if employee_number != list.JobNumber {
  777. c.ServeSuccessJSON(map[string]interface{}{
  778. "doubleCheck": check,
  779. "msg": "2",
  780. })
  781. return
  782. }
  783. }
  784. if check.ID > 0 {
  785. if employee_number != list.JobNumber {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "doubleCheck": check,
  788. "msg": "2",
  789. })
  790. return
  791. }
  792. }
  793. }
  794. doubleCheck := models.DoubleCheck{
  795. UserOrgId: adminUserInfo.Org.Id,
  796. PatientId: id,
  797. DialysisItemCheck: dialysis_item_check,
  798. DialysisParameterCheck: dialysis_parameter_check,
  799. VascularAccessVerification: vascular_access_verification,
  800. PipelineConnectionCheck: pipeline_connection_check,
  801. DialysisItemDesc: dialysis_item_desc,
  802. DialysisParameterDesc: dialysis_parameter_desc,
  803. VascularAccessDesc: vascular_access_desc,
  804. PipelineConnectionDesc: pipeline_connection_desc,
  805. Collator: collator,
  806. Status: 1,
  807. CreatedTime: time.Now().Unix(),
  808. CheckDate: recordDate.Unix(),
  809. UpdatedTime: time.Now().Unix(),
  810. EmployeeNumber: employee_number,
  811. DialyzerBatchNumber: dialyzer_batch_number,
  812. NeedleBatchNumber: needle_batch_number,
  813. }
  814. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  815. if check.ID == 0 { //新增
  816. doubleCheck.FirstCheckTime = firstCheckDate
  817. doubleCheck.CheckTime = checkDate
  818. doubleCheck.Creater = creater
  819. doubleCheck.Modifier = modifier
  820. if adminUserInfo.Org.Id == 10340 {
  821. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  822. doubleCheck.Creater = order.StartNurse
  823. }
  824. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  825. //查询未核对的医嘱
  826. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  827. for _, advice := range doctorList {
  828. if advice.ExecutionStaff == modifier {
  829. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  830. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  831. return
  832. }
  833. }
  834. }
  835. // 查询信息规挡的设置天数
  836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  837. if infor.ID > 0 && infor.WeekDay > 0 {
  838. var cha_time int64
  839. timeNowStr := time.Now().Format("2006-01-02")
  840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  841. //今日的日期减去设置的日期
  842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  843. if cha_time >= recordDate.Unix() {
  844. //查询审核是否允许
  845. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  846. //申请状态不允许的情况 拒绝修改
  847. if infor.ApplicationStatus != 1 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  849. return
  850. }
  851. }
  852. }
  853. err := service.AddSigleDoubleCheck(&doubleCheck)
  854. finish := models.XtDialysisFinish{
  855. IsFinish: 1,
  856. UserOrgId: adminUserInfo.Org.Id,
  857. Status: 1,
  858. Ctime: time.Now().Unix(),
  859. Mtime: 0,
  860. Module: 5,
  861. RecordDate: recordDate.Unix(),
  862. Sourse: 1,
  863. PatientId: id,
  864. }
  865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  866. if dialysisFinish.ID == 0 {
  867. service.CreateDialysisFinish(finish)
  868. }
  869. //针对长沙南雅
  870. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  871. //查询未核对的医嘱
  872. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  873. if len(doctorList) > 0 && modifier > 0 {
  874. for _, advice := range doctorList {
  875. service.UpdateDoctorAdviceList(advice.ID, modifier)
  876. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  881. redis.Set(keyTwo, "", time.Second)
  882. theTime := time.Now()
  883. recordDate := theTime.Format("2006-01-02")
  884. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  885. redis.Set(keyFour, "", time.Second)
  886. defer redis.Close()
  887. }
  888. }
  889. }
  890. //针对溪康
  891. if adminUserInfo.Org.Id == 10721 {
  892. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  893. if len(adviceInfoList) > 0 {
  894. for _, item := range adviceInfoList {
  895. service.UpdateHisAdviceList(item.ID, creater)
  896. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  897. redis := service.RedisClient()
  898. //清空key 值
  899. redis.Set(key, "", time.Second)
  900. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  901. redis.Set(keyTwo, "", time.Second)
  902. theTime := time.Now()
  903. recordDate := theTime.Format("2006-01-02")
  904. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  905. redis.Set(keyFour, "", time.Second)
  906. defer redis.Close()
  907. }
  908. }
  909. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  910. if len(adviceList) > 0 {
  911. for _, item := range adviceList {
  912. service.UpdateAdviceList(item.ID, creater)
  913. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  914. redis := service.RedisClient()
  915. //清空key 值
  916. redis.Set(key, "", time.Second)
  917. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  918. redis.Set(keyTwo, "", time.Second)
  919. theTime := time.Now()
  920. recordDate := theTime.Format("2006-01-02")
  921. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  922. redis.Set(keyFour, "", time.Second)
  923. defer redis.Close()
  924. }
  925. }
  926. }
  927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  928. redis := service.RedisClient()
  929. //清空key 值
  930. redis.Set(key, "", time.Second)
  931. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  932. redis.Set(keyOne, "", time.Second)
  933. defer redis.Close()
  934. if err == nil {
  935. c.ServeSuccessJSON(map[string]interface{}{
  936. "doubleCheck": &doubleCheck,
  937. })
  938. }
  939. } else { //修改
  940. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  941. if infor.ID > 0 {
  942. var cha_time int64
  943. timeNowStr := time.Now().Format("2006-01-02")
  944. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  945. //今日的日期减去设置的日期
  946. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  947. if cha_time >= recordDate.Unix() {
  948. //查询审核是否允许
  949. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  950. //申请状态不允许的情况 拒绝修改
  951. if infor.ApplicationStatus != 1 {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  953. return
  954. }
  955. }
  956. }
  957. doubleCheck.FirstCheckTime = firstCheckDate
  958. doubleCheck.CheckTime = checkDate
  959. doubleCheck.Creater = creater
  960. doubleCheck.Modifier = modifier
  961. doubleCheck.CreatedTime = check.CreatedTime
  962. doubleCheck.ID = check.ID
  963. doubleCheck.EmployeeNumber = employee_number
  964. doubleCheck.NeedleBatchNumber = needle_batch_number
  965. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  966. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  967. //查询未核对的医嘱
  968. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  969. for _, advice := range doctorList {
  970. if advice.ExecutionStaff == modifier {
  971. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  972. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  973. return
  974. }
  975. }
  976. }
  977. //针对溪康
  978. if adminUserInfo.Org.Id == 10721 {
  979. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  980. if len(adviceInfoList) > 0 {
  981. for _, item := range adviceInfoList {
  982. service.UpdateHisAdviceList(item.ID, creater)
  983. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  984. redis := service.RedisClient()
  985. //清空key 值
  986. redis.Set(key, "", time.Second)
  987. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  988. redis.Set(keyTwo, "", time.Second)
  989. theTime := time.Now()
  990. recordDate := theTime.Format("2006-01-02")
  991. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  992. redis.Set(keyFour, "", time.Second)
  993. defer redis.Close()
  994. }
  995. }
  996. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  997. if len(adviceList) > 0 {
  998. for _, item := range adviceList {
  999. service.UpdateAdviceList(item.ID, creater)
  1000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1001. redis := service.RedisClient()
  1002. //清空key 值
  1003. redis.Set(key, "", time.Second)
  1004. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1005. redis.Set(keyTwo, "", time.Second)
  1006. theTime := time.Now()
  1007. recordDate := theTime.Format("2006-01-02")
  1008. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1009. redis.Set(keyFour, "", time.Second)
  1010. defer redis.Close()
  1011. }
  1012. }
  1013. }
  1014. err := service.UpdateDoubleCheck(&doubleCheck)
  1015. //针对长沙南雅
  1016. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1017. //查询未核对的医嘱
  1018. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1019. if len(doctorList) > 0 && modifier > 0 {
  1020. for _, advice := range doctorList {
  1021. service.UpdateDoctorAdviceList(advice.ID, modifier)
  1022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1023. redis := service.RedisClient()
  1024. //清空key 值
  1025. redis.Set(key, "", time.Second)
  1026. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1027. redis.Set(keyTwo, "", time.Second)
  1028. theTime := time.Now()
  1029. recordDate := theTime.Format("2006-01-02")
  1030. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1031. redis.Set(keyFour, "", time.Second)
  1032. defer redis.Close()
  1033. }
  1034. }
  1035. }
  1036. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyOne, "", time.Second)
  1042. defer redis.Close()
  1043. if err == nil {
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "doubleCheck": &doubleCheck,
  1046. "msg": "1",
  1047. })
  1048. }
  1049. }
  1050. }
  1051. func (c *DialysisAPIController) PostAcceptsAssessment() {
  1052. id, _ := c.GetInt64("patient", 0)
  1053. recordDateStr := c.GetString("record_date")
  1054. way, _ := c.GetInt64("way", 0)
  1055. consciousness, _ := c.GetInt64("consciousness", 0)
  1056. appetite, _ := c.GetInt64("appetite", 0)
  1057. condition, _ := c.GetInt64("condition", 0)
  1058. posture, _ := c.GetInt64("posture")
  1059. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1060. danger_level, _ := c.GetInt64("danger_level", 0)
  1061. intake, _ := c.GetInt64("intake", 0)
  1062. nutrition, _ := c.GetInt64("nutrition", 0)
  1063. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1064. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1065. score := c.GetString("score")
  1066. sick_condition_other := c.GetString("sick_condition_other")
  1067. //precaution, _ := c.GetInt64("precaution", 0)
  1068. precaution := c.GetString("precaution")
  1069. precaution_other := c.GetString("precaution_other")
  1070. psychological_other := c.GetString("psychological_other")
  1071. admission_number := c.GetString("admission_number")
  1072. tumble, _ := c.GetInt64("tumble")
  1073. diacrisis := c.GetString("diacrisis")
  1074. his_department := c.GetString("his_department")
  1075. his_bed := c.GetString("his_bed")
  1076. if id <= 0 {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. adminUserInfo := c.GetMobileAdminUserInfo()
  1081. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1082. if patient.ID == 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1084. return
  1085. }
  1086. //now := time.Now()
  1087. //year, month, day := now.Date()
  1088. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1089. //todayTimeStamp := today_time.Unix()
  1090. if len(recordDateStr) == 0 {
  1091. recordDateStr = time.Now().Format("2006-01-02")
  1092. }
  1093. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1094. if parseDateErr != nil {
  1095. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. // 查询信息规挡的设置天数
  1100. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1101. if infor.ID > 0 && infor.WeekDay > 0 {
  1102. var cha_time int64
  1103. timeNowStr := time.Now().Format("2006-01-02")
  1104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1105. //今日的日期减去设置的日期
  1106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1107. if cha_time >= recordDate.Unix() {
  1108. //查询审核是否允许
  1109. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1110. //申请状态不允许的情况 拒绝修改
  1111. if infor.ApplicationStatus != 1 {
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1113. return
  1114. }
  1115. }
  1116. }
  1117. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1118. if adminUserInfo.Org.Id == 10340 {
  1119. if condition == 1 {
  1120. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1121. if admission_number == "" {
  1122. admission_number = lastAcceptTreatment.AdmissionNumber
  1123. }
  1124. }
  1125. }
  1126. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1127. UserOrgId: adminUserInfo.Org.Id,
  1128. PatientId: id,
  1129. RecordDate: recordDate.Unix(),
  1130. Way: way,
  1131. Consciousness: consciousness,
  1132. Appetite: appetite,
  1133. Condition: condition,
  1134. SickCondition: sick_condition,
  1135. DangerLevel: danger_level,
  1136. Intake: intake,
  1137. Nutrition: nutrition,
  1138. PsychologicalAssessment: psychological_assessment,
  1139. PsychologicalAssessmentOther: psychological_assessment_other,
  1140. SickConditionOther: sick_condition_other,
  1141. Posture: posture,
  1142. CreatedTime: time.Now().Unix(),
  1143. UpdateTime: time.Now().Unix(),
  1144. Status: 1,
  1145. Score: score,
  1146. Precaution: precaution,
  1147. PrecautionOther: precaution_other,
  1148. PsychologicalOther: psychological_other,
  1149. AdmissionNumber: admission_number,
  1150. Tumble: tumble,
  1151. Diacrisis: diacrisis,
  1152. HisBed: his_bed,
  1153. HisDepartment: his_department,
  1154. }
  1155. if receiveTreatment.ID == 0 { //新增
  1156. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1157. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1158. finish := models.XtDialysisFinish{
  1159. IsFinish: 1,
  1160. UserOrgId: adminUserInfo.Org.Id,
  1161. Status: 1,
  1162. Ctime: time.Now().Unix(),
  1163. Mtime: 0,
  1164. Module: 2,
  1165. RecordDate: recordDate.Unix(),
  1166. Sourse: 1,
  1167. PatientId: id,
  1168. }
  1169. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1170. if dialysisFinish.ID == 0 {
  1171. service.CreateDialysisFinish(finish)
  1172. }
  1173. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1174. redis := service.RedisClient()
  1175. defer redis.Close()
  1176. //清空key 值
  1177. redis.Set(key, "", time.Second)
  1178. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1179. redis.Set(keyOne, "", time.Second)
  1180. if err == nil {
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "receiveTreatmentAsses": receiveTreatmentAsses,
  1183. })
  1184. }
  1185. } else { //修改
  1186. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1187. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1188. // if getPermissionErr != nil {
  1189. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1190. // return
  1191. // } else if headNursePermission == nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1193. // return
  1194. // }
  1195. //}
  1196. // 查询信息规挡的设置天数
  1197. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1198. if infor.ID > 0 && infor.WeekDay > 0 {
  1199. var cha_time int64
  1200. timeNowStr := time.Now().Format("2006-01-02")
  1201. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1202. //今日的日期减去设置的日期
  1203. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1204. if cha_time >= recordDate.Unix() {
  1205. //查询审核是否允许
  1206. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1207. //申请状态不允许的情况 拒绝修改
  1208. if infor.ApplicationStatus != 1 {
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1210. return
  1211. }
  1212. }
  1213. }
  1214. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1215. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1216. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1217. receiveTreatmentAsses.ID = receiveTreatment.ID
  1218. if adminUserInfo.Org.Id == 10340 {
  1219. if condition == 1 {
  1220. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1221. if receiveTreatmentAsses.AdmissionNumber == "" {
  1222. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1223. }
  1224. }
  1225. }
  1226. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1227. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1228. redis := service.RedisClient()
  1229. defer redis.Close()
  1230. //清空key 值
  1231. redis.Set(key, "", time.Second)
  1232. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1233. redis.Set(keyOne, "", time.Second)
  1234. if err == nil {
  1235. c.ServeSuccessJSON(map[string]interface{}{
  1236. "receiveTreatmentAsses": receiveTreatmentAsses,
  1237. })
  1238. }
  1239. }
  1240. }
  1241. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1242. id, _ := c.GetInt64("patient", 0)
  1243. recordDateStr := c.GetString("record_date")
  1244. weightAfter, _ := c.GetFloat("weight_after", 0)
  1245. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1246. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1247. fmt.Println("weight_loss", weightReduce)
  1248. temperature, _ := c.GetFloat("temperature", 0)
  1249. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1250. breathing_rate := c.GetString("breathing_rate")
  1251. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1252. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1253. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1254. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1255. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1256. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1257. cruor := c.GetString("cruor")
  1258. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1259. internalFistula := c.GetString("internal_fistula")
  1260. catheter := c.GetString("catheter")
  1261. complications := c.GetString("complication")
  1262. remark := c.GetString("remark")
  1263. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1264. dialysis_intakes := c.GetString("dialysis_intakes")
  1265. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1266. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1267. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1268. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1269. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1270. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1271. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1272. patientGose, _ := c.GetInt64("patient_gose", 0)
  1273. inpatientDepartment := c.GetString("inpatient_department")
  1274. observationContent := c.GetString("observation_content")
  1275. observationContentOther := c.GetString("observation_content_other")
  1276. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1277. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1278. in_advance_reason := c.GetString("in_advance_reason")
  1279. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1280. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1281. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1282. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1283. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1284. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1285. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1286. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1287. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1288. is_eat, _ := c.GetInt64("is_eat", 0)
  1289. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1290. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1291. channels, _ := c.GetInt64("channel", 0)
  1292. return_blood, _ := c.GetInt64("return_blood", 0)
  1293. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1294. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1295. dialysis_during, _ := c.GetFloat("dialysis_during")
  1296. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1297. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1298. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1299. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1300. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1301. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1302. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1303. setting_pressure := c.GetString("setting_pressure")
  1304. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1305. diastolic_pressure := c.GetString("diastolic_pressure")
  1306. other_complication := c.GetString("other_complication")
  1307. ktv := c.GetString("ktv")
  1308. urr := c.GetString("urr")
  1309. hypertenison, _ := c.GetInt64("hypertenison")
  1310. hypopiesia, _ := c.GetInt64("hypopiesia")
  1311. leave_office_method, _ := c.GetInt64("leave_office_method")
  1312. lapse, _ := c.GetInt64("lapse")
  1313. consciousness, _ := c.GetInt64("consciousness")
  1314. fallrisk, _ := c.GetInt64("fallrisk")
  1315. machine_run := c.GetString("machine_run")
  1316. after_urea := c.GetString("after_urea")
  1317. pip_coagulation := c.GetString("pip_coagulation")
  1318. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1319. transfusion_volume := c.GetString("transfusion_volume")
  1320. last_after_weight := c.GetString("last_after_weight")
  1321. displace_liqui_value := c.GetString("displace_liqui_value")
  1322. start_time := c.GetString("start_time")
  1323. symptom_after_dialysis_remark := c.GetString("symptom_after_dialysis_remark")
  1324. if id <= 0 {
  1325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1326. return
  1327. }
  1328. adminUserInfo := c.GetMobileAdminUserInfo()
  1329. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1330. if patient.ID == 0 {
  1331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1332. return
  1333. }
  1334. if len(recordDateStr) == 0 {
  1335. recordDateStr = time.Now().Format("2006-01-02")
  1336. }
  1337. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1338. fmt.Println("parseDateErr", parseDateErr)
  1339. if parseDateErr != nil {
  1340. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1342. return
  1343. }
  1344. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1345. //now := time.Now()
  1346. //year, month, day := now.Date()
  1347. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1348. //todayTimeStamp := today_time.Unix()
  1349. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1350. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1351. UserOrgId: adminUserInfo.Org.Id,
  1352. PatientId: id,
  1353. AssessmentDate: recordDate.Unix(),
  1354. Temperature: temperature,
  1355. PulseFrequency: pulse_frequency,
  1356. BreathingRate: breathing_rate,
  1357. SystolicBloodPressure: systolic_blood_pressure,
  1358. DiastolicBloodPressure: diastolic_blood_pressure,
  1359. ActualUltrafiltration: actual_ultrafiltration,
  1360. ActualDisplacement: actual_displacement,
  1361. ActualTreatmentHour: actualtreatHour,
  1362. ActualTreatmentMinute: actualtreatmin,
  1363. WeightAfter: weightAfter,
  1364. AdditionalWeight: additionalWeight,
  1365. WeightLoss: weightReduce,
  1366. Cruor: cruor,
  1367. SymptomAfterDialysis: symptomsAfterDialysi,
  1368. InternalFistula: internalFistula,
  1369. Catheter: catheter,
  1370. Complication: complications,
  1371. DialysisIntakes: dialysateVolume,
  1372. CreatedTime: time.Now().Unix(),
  1373. UpdatedTime: time.Now().Unix(),
  1374. Status: 1,
  1375. Remark: remark,
  1376. BloodAccessPartId: blood_access_part_id,
  1377. BloodAccessPartOperaId: blood_access_part_opera_id,
  1378. DialysisIntakesUnit: dialysis_intakes_unit,
  1379. PuncturePointOozingBlood: puncturePointOozingBlood,
  1380. PuncturePointHaematoma: puncturePointHaematoma,
  1381. InternalFistulaTremorAc: internalFistulaTremorAc,
  1382. PatientGose: patientGose,
  1383. InpatientDepartment: inpatientDepartment,
  1384. ObservationContent: observationContent,
  1385. ObservationContentOther: observationContentOther,
  1386. DialysisProcess: dialysis_process,
  1387. InAdvanceMinute: in_advance_minute,
  1388. InAdvanceReason: in_advance_reason,
  1389. HemostasisMinute: hemostasis_minute,
  1390. HemostasisOpera: hemostasis_opera,
  1391. TremorNoise: tremor_noise,
  1392. DisequilibriumSyndrome: disequilibrium_syndrome,
  1393. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1394. ArterialTube: arterial_tube,
  1395. IntravenousTube: intravenous_tube,
  1396. Dialyzer: dialyzer,
  1397. InAdvanceReasonOther: in_advance_reason_other,
  1398. IsEat: is_eat,
  1399. CvcA: cvc_a,
  1400. CvcV: cvc_v,
  1401. Channel: channels,
  1402. ReturnBlood: return_blood,
  1403. RehydrationVolume: rehydration_volume,
  1404. DialysisDuring: dialysis_during,
  1405. StrokeVolume: stroke_volume,
  1406. BloodFlow: blood_flow,
  1407. SealingFluidDispose: sealing_fluid_dispose,
  1408. SealingFluidSpecial: sealing_fluid_special,
  1409. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1410. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1411. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1412. SettingPressure: setting_pressure,
  1413. DiastolicPressure: diastolic_pressure,
  1414. OtherComplication: other_complication,
  1415. Ktv: ktv,
  1416. Urr: urr,
  1417. Hypopiesia: hypopiesia,
  1418. Hypertenison: hypertenison,
  1419. Lapse: lapse,
  1420. LeaveOfficeMethod: leave_office_method,
  1421. Consciousness: consciousness,
  1422. Fallrisk: fallrisk,
  1423. MachineRun: machine_run,
  1424. AfterUrea: after_urea,
  1425. PipCoagulation: pip_coagulation,
  1426. AccumulatedBloodVolume: accumulated_blood_volume,
  1427. TransfusionVolume: transfusion_volume,
  1428. LastAfterWeight: last_after_weight,
  1429. DisplaceLiquiValue: displace_liqui_value,
  1430. RecordTime: startDate.Unix(),
  1431. SymptomAfterDialysisRemark: symptom_after_dialysis_remark,
  1432. }
  1433. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1434. // 查询信息规挡的设置天数
  1435. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1436. if infor.ID > 0 && infor.WeekDay > 0 {
  1437. var cha_time int64
  1438. timeNowStr := time.Now().Format("2006-01-02")
  1439. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1440. //今日的日期减去设置的日期
  1441. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1442. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1443. if cha_time >= recordDate.Unix() {
  1444. //查询审核是否允许
  1445. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1446. //申请状态不允许的情况 拒绝修改
  1447. if infor.ApplicationStatus != 1 {
  1448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1449. return
  1450. }
  1451. }
  1452. }
  1453. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1454. if assessmentAfter.ID == 0 { //新增
  1455. if appRole.UserType == 2 || appRole.UserType == 1 {
  1456. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1457. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1458. } else {
  1459. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1460. }
  1461. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1462. if assessmentAfterDislysis.UserOrgId != 10340 {
  1463. if assessmentAfterDislysis.WeightAfter == 0 {
  1464. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1465. }
  1466. }
  1467. if adminUserInfo.Org.Id == 10693 {
  1468. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1469. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1470. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1471. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1472. }
  1473. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1474. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1475. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1476. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1477. }
  1478. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1479. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1480. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1481. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1482. }
  1483. if assessmentAfterDislysis.PulseFrequency == 0 {
  1484. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1485. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1486. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1487. }
  1488. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1489. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1490. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1491. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1492. }
  1493. }
  1494. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1495. //记录日志
  1496. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1497. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1498. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1499. PatientId: assessmentAfterDislysis.PatientId,
  1500. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1501. Status: 1,
  1502. ErrLog: string(byterequest),
  1503. AdminUserId: adminUserInfo.AdminUser.Id,
  1504. Ctime: 0,
  1505. Mtime: 0,
  1506. Source: "手机端保存透后评估",
  1507. }
  1508. service.CreateAfterDialysisLog(afterDialysisLog)
  1509. finish := models.XtDialysisFinish{
  1510. IsFinish: 1,
  1511. UserOrgId: adminUserInfo.Org.Id,
  1512. Status: 1,
  1513. Ctime: time.Now().Unix(),
  1514. Mtime: 0,
  1515. Module: 9,
  1516. RecordDate: recordDate.Unix(),
  1517. Sourse: 1,
  1518. PatientId: id,
  1519. }
  1520. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1521. if dialysisFinish.ID == 0 {
  1522. service.CreateDialysisFinish(finish)
  1523. }
  1524. redis := service.RedisClient()
  1525. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1526. redis.Set(keyTwo, "", time.Second)
  1527. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1528. //清空key 值
  1529. redis.Set(key, "", time.Second)
  1530. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1531. redis.Set(keyOne, "", time.Second)
  1532. defer redis.Close()
  1533. if err == nil {
  1534. c.ServeSuccessJSON(map[string]interface{}{
  1535. "assessmentAfterDislysis": assessmentAfterDislysis,
  1536. })
  1537. }
  1538. return
  1539. } else { //修改
  1540. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1541. if infor.ID > 0 && infor.WeekDay > 0 {
  1542. var cha_time int64
  1543. timeNowStr := time.Now().Format("2006-01-02")
  1544. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1545. //今日的日期减去设置的日期
  1546. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1547. if cha_time >= recordDate.Unix() {
  1548. //查询审核是否允许
  1549. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1550. //申请状态不允许的情况 拒绝修改
  1551. if infor.ApplicationStatus != 1 {
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1553. return
  1554. }
  1555. }
  1556. }
  1557. if appRole.UserType == 2 || appRole.UserType == 1 {
  1558. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1559. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1560. } else {
  1561. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1562. if assessmentAfterDislysis.Creater == 0 {
  1563. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1564. }
  1565. }
  1566. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1567. assessmentAfterDislysis.ID = assessmentAfter.ID
  1568. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1569. if assessmentAfterDislysis.UserOrgId != 10340 {
  1570. if assessmentAfterDislysis.WeightAfter == 0 {
  1571. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1572. }
  1573. }
  1574. if adminUserInfo.Org.Id == 10693 {
  1575. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1576. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1577. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1578. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1579. }
  1580. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1581. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1582. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1583. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1584. }
  1585. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1586. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1587. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1588. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1589. }
  1590. if assessmentAfterDislysis.PulseFrequency == 0 {
  1591. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1592. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1593. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1594. }
  1595. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1596. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1597. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1598. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1599. }
  1600. }
  1601. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1602. //记录日志
  1603. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1604. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1605. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1606. PatientId: assessmentAfterDislysis.PatientId,
  1607. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1608. Status: 1,
  1609. ErrLog: string(byterequest),
  1610. AdminUserId: adminUserInfo.AdminUser.Id,
  1611. Ctime: time.Now().Unix(),
  1612. Mtime: 0,
  1613. Source: "手机端修改保存透后评估",
  1614. }
  1615. service.CreateAfterDialysisLog(afterDialysisLog)
  1616. redis := service.RedisClient()
  1617. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1618. redis.Set(keyTwo, "", time.Second)
  1619. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1620. //清空key 值
  1621. redis.Set(key, "", time.Second)
  1622. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1623. redis.Set(keyOne, "", time.Second)
  1624. if err == nil {
  1625. c.ServeSuccessJSON(map[string]interface{}{
  1626. "assessmentAfterDislysis": assessmentAfterDislysis,
  1627. })
  1628. return
  1629. }
  1630. }
  1631. return
  1632. }
  1633. func (c *DialysisAPIController) PostDialysisPrescription() {
  1634. id, _ := c.GetInt64("patient", 0)
  1635. recordDateStr := c.GetString("record_date")
  1636. if id <= 0 {
  1637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1638. return
  1639. }
  1640. adminUserInfo := c.GetMobileAdminUserInfo()
  1641. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1642. if patient.ID == 0 {
  1643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1644. return
  1645. }
  1646. if len(recordDateStr) == 0 {
  1647. recordDateStr = time.Now().Format("2006-01-02")
  1648. }
  1649. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1650. if parseDateErr != nil {
  1651. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1653. return
  1654. }
  1655. mode_id, _ := c.GetInt64("mode_id", 0)
  1656. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1657. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1658. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1659. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1660. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1661. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1662. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1663. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1664. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1665. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1666. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1667. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1668. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1669. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1670. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1671. kalium, _ := c.GetFloat("kalium", 0)
  1672. sodium, _ := c.GetFloat("sodium", 0)
  1673. calcium, _ := c.GetFloat("calcium", 0)
  1674. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1675. glucose, _ := c.GetFloat("glucose", 0)
  1676. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1677. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1678. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1679. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1680. conductivity, _ := c.GetFloat("conductivity", 0)
  1681. remark := c.GetString("remark")
  1682. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1683. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1684. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1685. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1686. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1687. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1688. special_medicine_other := c.GetString("special_medicine_other")
  1689. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1690. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1691. blood_access, _ := c.GetInt64("blood_access", 0)
  1692. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1693. body_fluid_other := c.GetString("body_fluid_other")
  1694. niprocart, _ := c.GetInt64("niprocart", 0)
  1695. jms, _ := c.GetInt64("jms", 0)
  1696. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1697. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1698. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1699. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1700. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1701. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1702. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1703. injector, _ := c.GetInt64("injector", 0)
  1704. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1705. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1706. safe_package, _ := c.GetInt64("package", 0)
  1707. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1708. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1709. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1710. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1711. blood := c.GetString("blood")
  1712. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1713. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1714. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1715. displace_speed := c.GetString("displace_speed")
  1716. illness, _ := c.GetInt64("illness")
  1717. amylaceum := c.GetString("amylaceum")
  1718. single_time := c.GetString("single_time")
  1719. single_water := c.GetString("single_water")
  1720. replacement_flow := c.GetString("replacement_flow")
  1721. plasma_separator := c.GetString("plasma_separator")
  1722. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1723. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1724. oxygen_flow := c.GetString("oxygen_flow")
  1725. oxygen_time := c.GetString("oxygen_time")
  1726. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1727. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1728. puncture_needle := c.GetString("puncture_needle")
  1729. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1730. epo := c.GetString("epo")
  1731. epo_count, _ := c.GetFloat("epo_count", 0)
  1732. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1733. admin_user_id, _ := c.GetInt64("admin_user_id")
  1734. is_water := c.GetString("is_water")
  1735. var is_war int64
  1736. if is_water == "是" {
  1737. is_war = 1
  1738. }
  1739. if is_water == "否" {
  1740. is_war = 2
  1741. }
  1742. if is_water == "请选择" {
  1743. is_war = 0
  1744. }
  1745. drhy_water := c.GetString("drhy_water")
  1746. dry_water_hour := c.GetString("dry_water_hour")
  1747. water_machine := c.GetString("water_machine")
  1748. add_amount, _ := c.GetFloat("add_amount")
  1749. reduce_amount, _ := c.GetFloat("reduce_amount")
  1750. dialysis_remark := c.GetString("dialysis_remark")
  1751. prescribing_number, _ := c.GetFloat("prescribing_number")
  1752. prescription_sodium := c.GetString("prescription_sodium")
  1753. start_sodium := c.GetString("start_sodium")
  1754. sodium_curve := c.GetString("sodium_curve")
  1755. treatment_remark := c.GetString("treatment_remark")
  1756. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1757. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1758. prescription_water, _ := c.GetFloat("prescription_water")
  1759. dialysis_strainer := c.GetString("dialysis_strainer")
  1760. chaptalization := c.GetString("chaptalization")
  1761. washing_time := c.GetString("washing_time")
  1762. warsh_count := c.GetString("warsh_count")
  1763. blood_access_part_id := c.GetString("blood_access_part_id")
  1764. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1765. dialyzate := c.GetString("dialyzate")
  1766. first_super := c.GetString("first_super")
  1767. var first_sup int64
  1768. if first_super == "是" {
  1769. first_sup = 1
  1770. }
  1771. if first_super == "否" {
  1772. first_sup = 2
  1773. }
  1774. if first_super == "请选择" {
  1775. first_sup = 0
  1776. }
  1777. is_sequential := c.GetString("is_sequential")
  1778. var is_sequent int64
  1779. if is_sequential == "是" {
  1780. is_sequent = 1
  1781. }
  1782. if is_sequential == "否" {
  1783. is_sequent = 2
  1784. }
  1785. if is_sequential == "请选择" {
  1786. is_sequent = 0
  1787. }
  1788. conduct := c.GetString("conduct")
  1789. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1790. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1791. //
  1792. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1793. // if appRole.UserType == 3 {
  1794. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1795. // if getPermissionErr != nil {
  1796. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1797. // return
  1798. // } else if headNursePermission == nil {
  1799. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1800. // return
  1801. // }
  1802. // }
  1803. //}
  1804. // 查询信息规挡的设置天数
  1805. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1806. if infor.ID > 0 && infor.WeekDay > 0 {
  1807. var cha_time int64
  1808. timeNowStr := time.Now().Format("2006-01-02")
  1809. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1810. //今日的日期减去设置的日期
  1811. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1812. if cha_time >= recordDate.Unix() {
  1813. //查询审核是否允许
  1814. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1815. //申请状态不允许的情况 拒绝修改
  1816. if infor.ApplicationStatus != 1 {
  1817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1818. return
  1819. }
  1820. }
  1821. }
  1822. if mode_id > 0 {
  1823. var str string
  1824. //查找该机构用的是什么透析器
  1825. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1826. if filedConfig.ID > 0 {
  1827. str = dialyzerPerfusionApparatus
  1828. } else {
  1829. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1830. }
  1831. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1832. }
  1833. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1834. var dialysis_dialyszers_id int64
  1835. var dialysis_strainer_id int64
  1836. var dialysis_irrigation_id int64
  1837. if len(goodList) > 0 {
  1838. for _, item := range goodList {
  1839. if item.SpecificationName == dialysis_dialyszers {
  1840. dialysis_dialyszers_id = item.ID
  1841. }
  1842. if item.SpecificationName == dialysis_irrigation {
  1843. dialysis_irrigation_id = item.ID
  1844. }
  1845. if item.SpecificationName == dialysis_strainer {
  1846. dialysis_strainer_id = item.ID
  1847. }
  1848. }
  1849. }
  1850. //TODO 需要根据角色去判断
  1851. prescription := models.DialysisPrescription{
  1852. UserOrgId: adminUserInfo.Org.Id,
  1853. PatientId: id,
  1854. RecordDate: recordDate.Unix(),
  1855. ModeId: mode_id,
  1856. DialysisDuration: dialysis_duration,
  1857. Dialyzer: dialyzer,
  1858. PerfusionApparatus: perfusion_apparatus,
  1859. BloodFlowVolume: blood_flow_volume,
  1860. DewaterAmount: dewater_amount,
  1861. DisplaceLiqui: displace_liqui,
  1862. ReplacementWay: replacement_way,
  1863. Anticoagulant: anticoagulant,
  1864. AnticoagulantShouji: anticoagulant_shouji,
  1865. AnticoagulantWeichi: anticoagulant_weichi,
  1866. AnticoagulantZongliang: anticoagulant_zongliang,
  1867. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1868. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1869. Kalium: kalium,
  1870. Sodium: sodium,
  1871. Calcium: calcium,
  1872. Bicarbonate: bicarbonate,
  1873. Glucose: glucose,
  1874. // DryWeight: dry_weight,
  1875. DialysateFlow: dialysate_flow,
  1876. DialysateTemperature: dialysate_temperature,
  1877. // PrescriptionDoctor: prescription_doctor,
  1878. ReplacementTotal: replacement_total,
  1879. Conductivity: conductivity,
  1880. Remark: remark,
  1881. Status: 1,
  1882. CreatedTime: time.Now().Unix(),
  1883. UpdatedTime: time.Now().Unix(),
  1884. DialysisDurationMinute: dialysisDurationMinute,
  1885. DialysisDurationHour: dialysisDurationHour,
  1886. TargetUltrafiltration: targetUltrafiltration,
  1887. DialysateFormulation: dialysateFormulation,
  1888. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1889. BodyFluid: body_fluid,
  1890. SpecialMedicine: special_medicine,
  1891. SpecialMedicineOther: special_medicine_other,
  1892. DisplaceLiquiPart: displace_liqui_part,
  1893. DisplaceLiquiValue: displace_liqui_value,
  1894. BloodAccess: blood_access,
  1895. Ultrafiltration: ultrafiltration,
  1896. BodyFluidOther: body_fluid_other,
  1897. Niprocart: niprocart,
  1898. Jms: jms,
  1899. FistulaNeedleSet: fistula_needle_set,
  1900. FistulaNeedleSet16: fistula_needle_set_16,
  1901. Hemoperfusion: hemoperfusion,
  1902. DialyserSterilised: dialyser_sterilised,
  1903. Filtryzer: filtryzer,
  1904. Dialyzers: dialyzers,
  1905. Injector: injector,
  1906. Bloodlines: bloodlines,
  1907. TubingHemodialysis: tubing_hemodialysis,
  1908. Package: safe_package,
  1909. ALiquid: a_liquid,
  1910. TargetKtv: target_ktv,
  1911. PreImpulse: pre_impulse,
  1912. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1913. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1914. Blood: blood,
  1915. DialysisDialyszers: dialysis_dialyszers,
  1916. DialysisIrrigation: dialysis_irrigation,
  1917. AntioxidantCommodityName: antioxidant_commodity_name,
  1918. DisplaceSpeed: displace_speed,
  1919. Illness: illness,
  1920. Amylaceum: amylaceum,
  1921. SingleTime: single_time,
  1922. SingleWater: single_water,
  1923. ReplacementFlow: replacement_flow,
  1924. PlasmaSeparator: plasma_separator,
  1925. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1926. OxygenUptake: oxygen_uptake,
  1927. OxygenFlow: oxygen_flow,
  1928. OxygenTime: oxygen_time,
  1929. HemodialysisPipelines: hemodialysis_pipelines,
  1930. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1931. PunctureNeedle: puncture_needle,
  1932. PunctureNeedleCount: puncture_needle_count,
  1933. Epo: epo,
  1934. EpoCount: epo_count,
  1935. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1936. AdminUserId: admin_user_id,
  1937. IsWater: is_war,
  1938. DrhyWater: drhy_water,
  1939. DryWaterHour: dry_water_hour,
  1940. WaterMachine: water_machine,
  1941. AddAmount: add_amount,
  1942. ReduceAmount: reduce_amount,
  1943. DialysisRemark: dialysis_remark,
  1944. PrescribingNumber: prescribing_number,
  1945. StartSodium: start_sodium,
  1946. SodiumCurve: sodium_curve,
  1947. TreatmentRemark: treatment_remark,
  1948. PrescriptionSodium: prescription_sodium,
  1949. DialysisFluidFlow: dialysis_fluid_flow,
  1950. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1951. PrescriptionWater: prescription_water,
  1952. DialysisStrainer: dialysis_strainer,
  1953. Chaptalization: chaptalization,
  1954. WashingTime: washing_time,
  1955. WarshCount: warsh_count,
  1956. BloodAccessPartId: blood_access_part_id,
  1957. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1958. Dialyzate: dialyzate,
  1959. DialysisDialyszersId: dialysis_dialyszers_id,
  1960. DialysisIrrigationId: dialysis_irrigation_id,
  1961. DialysisStrainerId: dialysis_strainer_id,
  1962. FirstSuper: first_sup,
  1963. IsSequential: is_sequent,
  1964. Conduct: conduct,
  1965. }
  1966. if adminUserInfo.Org.Id == 10721 {
  1967. if prescription.ModeId == 2 {
  1968. if prescription.ReplacementTotal == 0 {
  1969. prescription.ReplacementTotal = 15
  1970. }
  1971. }
  1972. }
  1973. //查询最近透析准备表里是否存在 透析器 灌流器
  1974. //
  1975. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1976. //
  1977. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1978. //
  1979. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1980. //if len(mation)>0{
  1981. // for _, item := range splitStr {
  1982. // for _,it := range mation{
  1983. // if(item == it.SpecificationName){
  1984. //
  1985. // //查询最近一次的透析器
  1986. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1987. //
  1988. // if errcode == gorm.ErrRecordNotFound{
  1989. // //插入数据
  1990. // prepare := models.DialysisBeforePrepare{
  1991. // UserOrgId: adminUserInfo.Org.Id,
  1992. // PatientId: id,
  1993. // RecordDate: recordDate.Unix(),
  1994. // GoodTypeId: it.GoodTypeId,
  1995. // GoodId: it.ID,
  1996. // Count: 1,
  1997. // Ctime: time.Now().Unix(),
  1998. // Creater: adminUserInfo.AdminUser.Id,
  1999. // Status:1,
  2000. //
  2001. // }
  2002. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2003. // fmt.Println("",errcode)
  2004. // }
  2005. // }
  2006. // }
  2007. //
  2008. // }
  2009. //
  2010. // for _, item := range splitIrrigation {
  2011. // for _,it := range mation{
  2012. // if(item == it.SpecificationName){
  2013. // //查询最近一次的透析器
  2014. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2015. // if errcode == gorm.ErrRecordNotFound{
  2016. // //插入数据
  2017. // prepare := models.DialysisBeforePrepare{
  2018. // UserOrgId: adminUserInfo.Org.Id,
  2019. // PatientId: id,
  2020. // RecordDate: recordDate.Unix(),
  2021. // GoodTypeId: it.GoodTypeId,
  2022. // GoodId: it.ID,
  2023. // Count: 1,
  2024. // Ctime: time.Now().Unix(),
  2025. // Creater: adminUserInfo.AdminUser.Id,
  2026. // Status:1,
  2027. //
  2028. // }
  2029. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2030. // fmt.Println(errcode)
  2031. // }
  2032. // }
  2033. // }
  2034. // }
  2035. //}
  2036. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2037. if dialysisPrescription.ID == 0 { //新增
  2038. if appRole.UserType == 2 || appRole.UserType == 1 {
  2039. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2040. }
  2041. prescription.Creater = adminUserInfo.AdminUser.Id
  2042. //针对河间咸得
  2043. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2044. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2045. prescription.DisplaceLiquiPart = 0
  2046. prescription.DisplaceLiquiValue = 0
  2047. }
  2048. }
  2049. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2050. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2051. }
  2052. err := service.AddSigleRecord(&prescription)
  2053. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2054. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2055. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2056. if len(monitorList) > 0 {
  2057. var ultrafiltration_rate float64
  2058. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2059. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2060. var replacement_rate float64
  2061. //乘10 除10是为了保留一位小数
  2062. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2063. var firstOpeateTime = monitorList[0].OperateTime
  2064. for _, item := range monitorList {
  2065. //超滤率
  2066. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2067. //置换率
  2068. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2069. //超滤量
  2070. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2071. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2072. //置换量
  2073. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2074. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2075. }
  2076. }
  2077. }
  2078. //记录日志
  2079. byterequest, _ := json.Marshal(prescription)
  2080. prescriptionLog := models.XtDialysisPrescriptionLog{
  2081. UserOrgId: prescription.UserOrgId,
  2082. Ctime: time.Now().Unix(),
  2083. Mtime: 0,
  2084. ErrLog: string(byterequest),
  2085. AdminUserId: adminUserInfo.AdminUser.Id,
  2086. RecordDate: prescription.RecordDate,
  2087. PatientId: prescription.PatientId,
  2088. Source: "手机端新增保存处方",
  2089. Status: 1,
  2090. }
  2091. service.CreatePrescriptionLog(prescriptionLog)
  2092. finish := models.XtDialysisFinish{
  2093. IsFinish: 1,
  2094. UserOrgId: adminUserInfo.Org.Id,
  2095. Status: 1,
  2096. Ctime: time.Now().Unix(),
  2097. Mtime: 0,
  2098. Module: 1,
  2099. RecordDate: recordDate.Unix(),
  2100. Sourse: 1,
  2101. PatientId: id,
  2102. }
  2103. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2104. if dialysisFinish.ID == 0 {
  2105. service.CreateDialysisFinish(finish)
  2106. }
  2107. //长沙南雅医院,自动生成抗凝剂的临时处方
  2108. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2109. if prescribing_number == 0 {
  2110. prescribing_number = 1
  2111. }
  2112. if prescribing_number == 0 && id == 14682 {
  2113. prescribing_number = 2
  2114. }
  2115. if prescribing_number == 0 && id == 18560 {
  2116. prescribing_number = 2
  2117. }
  2118. advice := models.DoctorAdvice{
  2119. UserOrgId: adminUserInfo.Org.Id,
  2120. PatientId: id,
  2121. GroupNo: 0,
  2122. AdviceType: 2,
  2123. RecordDate: recordDate.Unix(),
  2124. AdviceDate: recordDate.Unix(),
  2125. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2126. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2127. AdviceDesc: "",
  2128. ReminderDate: 0,
  2129. SingleDose: anticoagulant_zongliang,
  2130. SingleDoseUnit: "iu",
  2131. DrugSpec: 0,
  2132. DrugSpecUnit: "",
  2133. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2134. PrescribingNumberUnit: "支",
  2135. DeliveryWay: "静脉注射",
  2136. ExecutionFrequency: "上机前",
  2137. AdviceDoctor: 0,
  2138. Status: 1,
  2139. CreatedTime: time.Now().Unix(),
  2140. UpdatedTime: time.Now().Unix(),
  2141. IsPrescription: 1,
  2142. ExecutionState: 2,
  2143. StopState: 2,
  2144. IsSettle: 2,
  2145. }
  2146. // 查询排班信息
  2147. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2148. if schedulePatient.ID > 0 {
  2149. if schedulePatient.ScheduleType == 1 {
  2150. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2151. }
  2152. if schedulePatient.ScheduleType == 2 {
  2153. advice.StartTime = recordDate.Unix() + 9*60*60
  2154. }
  2155. }
  2156. // 抗凝剂名称
  2157. switch anticoagulant {
  2158. case 1:
  2159. advice.AdviceName = "无肝素"
  2160. break
  2161. case 2:
  2162. advice.AdviceName = "普通肝素"
  2163. break
  2164. case 3:
  2165. advice.AdviceName = "低分子肝素"
  2166. break
  2167. case 4:
  2168. advice.AdviceName = "阿加曲班"
  2169. break
  2170. case 5:
  2171. advice.AdviceName = "枸橼酸钠"
  2172. break
  2173. case 6:
  2174. advice.AdviceName = "低分子肝素钙"
  2175. break
  2176. case 7:
  2177. advice.AdviceName = "低分子肝素钠"
  2178. break
  2179. case 8:
  2180. advice.AdviceName = "依诺肝素"
  2181. break
  2182. case 9:
  2183. advice.AdviceName = "达肝素"
  2184. break
  2185. case 10:
  2186. advice.AdviceName = "体外抗凝"
  2187. break
  2188. case 11:
  2189. advice.AdviceName = "那曲肝素"
  2190. break
  2191. case 12:
  2192. advice.AdviceName = "无抗凝剂"
  2193. break
  2194. }
  2195. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2196. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2197. advice.AdviceDoctor = appRole.AdminUserId
  2198. }
  2199. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2200. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2201. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2202. advice.AdviceName = "低分子肝素钠注射液"
  2203. // 修改患者临时医嘱里的抗凝剂医嘱
  2204. advice.ID = advicePrescription.ID
  2205. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2206. } else {
  2207. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2208. advice.AdviceName = "低分子肝素钠注射液"
  2209. // 新增患者临时医嘱里的抗凝剂医嘱
  2210. service.CreateDoctorAdvice(&advice)
  2211. }
  2212. }
  2213. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2214. redis := service.RedisClient()
  2215. defer redis.Close()
  2216. //清空key 值
  2217. redis.Set(key, "", time.Second)
  2218. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2219. redis.Set(keyOne, "", time.Second)
  2220. }
  2221. //获取key,清空redis
  2222. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2223. redis := service.RedisClient()
  2224. //清空key 值
  2225. redis.Set(key, "", time.Second)
  2226. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2227. //清空key 值
  2228. redis.Set(keyOne, "", time.Second)
  2229. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2230. //清空key 值
  2231. redis.Set(keyTwo, "", time.Second)
  2232. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2233. redis.Set(keySix, "", time.Second)
  2234. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2235. redis.Set(keySeven, "", time.Second)
  2236. if err == nil {
  2237. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2238. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2239. //清空key 值
  2240. redis.Set(keyThree, "", time.Second)
  2241. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2242. //清空key 值
  2243. redis.Set(keyFour, "", time.Second)
  2244. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2245. redis.Set(keyFive, "", time.Second)
  2246. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2247. redis.Set(keySix, "", time.Second)
  2248. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2249. redis.Set(keySeven, "", time.Second)
  2250. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2251. //清空key 值
  2252. redis.Set(keyOne, "", time.Second)
  2253. if updateErr != nil {
  2254. utils.ErrorLog("%v", updateErr)
  2255. }
  2256. defer redis.Close()
  2257. c.ServeSuccessJSON(map[string]interface{}{
  2258. "prescription": prescription,
  2259. })
  2260. }
  2261. } else { //修改
  2262. //if mode_id > 0 {
  2263. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2264. //}
  2265. //if template.TemplateId == 1 {
  2266. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2267. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2268. // if getPermissionErr != nil {
  2269. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2270. // return
  2271. // } else if headNursePermission == nil {
  2272. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2273. // return
  2274. // }
  2275. // }
  2276. //}
  2277. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2278. prescription.Modifier = adminUserInfo.AdminUser.Id
  2279. if appRole.UserType == 2 || appRole.UserType == 1 {
  2280. prescription_doctor := adminUserInfo.AdminUser.Id
  2281. prescription.PrescriptionDoctor = prescription_doctor
  2282. } else {
  2283. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2284. }
  2285. if dialysisPrescription.Creater == 0 { //体重称
  2286. prescription.Creater = adminUserInfo.AdminUser.Id
  2287. } else {
  2288. prescription.Creater = dialysisPrescription.Creater
  2289. if adminUserInfo.Org.Id == 9882 {
  2290. if appRole.UserType == 2 || appRole.UserType == 1 {
  2291. prescription_doctor := adminUserInfo.AdminUser.Id
  2292. prescription.PrescriptionDoctor = prescription_doctor
  2293. prescription.Creater = prescription_doctor
  2294. }
  2295. }
  2296. }
  2297. prescription.ID = dialysisPrescription.ID
  2298. if adminUserInfo.Org.Id == 10721 {
  2299. if prescription.ModeId == 2 {
  2300. if prescription.ReplacementTotal == 0 {
  2301. prescription.ReplacementTotal = 15
  2302. }
  2303. }
  2304. }
  2305. service.UpDateDialysisPrescription(&prescription)
  2306. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2307. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2308. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2309. if len(monitorList) > 0 {
  2310. var ultrafiltration_rate float64
  2311. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2312. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2313. var replacement_rate float64
  2314. //乘10 除10是为了保留一位小数
  2315. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2316. var firstOpeateTime = monitorList[0].OperateTime
  2317. for _, item := range monitorList {
  2318. //超滤率
  2319. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2320. //置换率
  2321. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2322. //超滤量
  2323. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2324. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2325. //置换量
  2326. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2327. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2328. }
  2329. }
  2330. }
  2331. //记录日志
  2332. byterequest, _ := json.Marshal(prescription)
  2333. prescriptionLog := models.XtDialysisPrescriptionLog{
  2334. UserOrgId: prescription.UserOrgId,
  2335. Ctime: time.Now().Unix(),
  2336. Mtime: 0,
  2337. ErrLog: string(byterequest),
  2338. AdminUserId: adminUserInfo.AdminUser.Id,
  2339. RecordDate: prescription.RecordDate,
  2340. PatientId: prescription.PatientId,
  2341. Source: "手机端修改处方",
  2342. Status: 1,
  2343. }
  2344. service.CreatePrescriptionLog(prescriptionLog)
  2345. finish := models.XtDialysisFinish{
  2346. IsFinish: 1,
  2347. UserOrgId: adminUserInfo.Org.Id,
  2348. Status: 1,
  2349. Ctime: time.Now().Unix(),
  2350. Mtime: 0,
  2351. Module: 1,
  2352. RecordDate: recordDate.Unix(),
  2353. Sourse: 1,
  2354. PatientId: id,
  2355. }
  2356. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2357. if dialysisFinish.ID == 0 {
  2358. service.CreateDialysisFinish(finish)
  2359. }
  2360. //修改处方
  2361. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2362. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2363. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2364. if advicePrescription.ID > 0 {
  2365. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2366. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2367. redis := service.RedisClient()
  2368. defer redis.Close()
  2369. //清空key 值
  2370. redis.Set(key, "", time.Second)
  2371. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2372. redis.Set(keyOne, "", time.Second)
  2373. }
  2374. }
  2375. //获取key,清空redis
  2376. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2377. redis := service.RedisClient()
  2378. //清空key 值
  2379. redis.Set(key, "", time.Second)
  2380. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2381. //清空key 值
  2382. redis.Set(keyOne, "", time.Second)
  2383. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2384. redis.Set(keySix, "", time.Second)
  2385. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2386. redis.Set(keySeven, "", time.Second)
  2387. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2388. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2389. //清空key 值
  2390. redis.Set(keyTwoOne, "", time.Second)
  2391. defer redis.Close()
  2392. if updateErr != nil {
  2393. utils.ErrorLog("%v", updateErr)
  2394. }
  2395. c.ServeSuccessJSON(map[string]interface{}{
  2396. "prescription": prescription,
  2397. })
  2398. }
  2399. }
  2400. func (c *DialysisAPIController) Finish() {
  2401. id, _ := c.GetInt64("patient", 0)
  2402. recordDateStr := c.GetString("record_date")
  2403. nurseID, _ := c.GetInt64("nurse")
  2404. end_time := c.GetString("end_time")
  2405. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2406. internal_fistula := c.GetString("blood_access_internal_fistula")
  2407. catheter := c.GetString("catheter")
  2408. cruor := c.GetString("cruor")
  2409. mission := c.GetString("mission")
  2410. condenser := c.GetString("condenser")
  2411. if id <= 0 || nurseID <= 0 {
  2412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2413. return
  2414. }
  2415. adminUserInfo := c.GetMobileAdminUserInfo()
  2416. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2417. if patient.ID == 0 {
  2418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2419. return
  2420. }
  2421. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2422. if getNurseErr != nil {
  2423. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2425. return
  2426. } else if nurse == nil {
  2427. c.ErrorLog("护士不存在")
  2428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2429. return
  2430. }
  2431. if len(recordDateStr) == 0 {
  2432. recordDateStr = time.Now().Format("2006-01-02")
  2433. }
  2434. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2435. if parseDateErr != nil {
  2436. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2438. return
  2439. }
  2440. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2441. if parseEndDateErr != nil {
  2442. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2444. return
  2445. }
  2446. // 查询信息规挡的设置天数
  2447. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2448. if infor.ID > 0 && infor.WeekDay > 0 {
  2449. var cha_time int64
  2450. timeNowStr := time.Now().Format("2006-01-02")
  2451. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2452. //今日的日期减去设置的日期
  2453. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2454. if cha_time >= recordDate.Unix() {
  2455. //查询审核是否允许
  2456. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2457. //申请状态不允许的情况 拒绝修改
  2458. if infor.ApplicationStatus != 1 {
  2459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2460. return
  2461. }
  2462. }
  2463. }
  2464. //now := time.Now()
  2465. //year, month, day := now.Date()
  2466. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2467. //todayTimeStamp := today_time.Unix()
  2468. // 获取当天的第一条透析纪录
  2469. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2470. if getMonitorRecordsErr != nil {
  2471. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2473. return
  2474. }
  2475. // 获取当前的最后一条透析纪录
  2476. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2477. if getMonitorRecordsErr != nil {
  2478. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2480. return
  2481. }
  2482. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2483. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2484. if getAADErr != nil {
  2485. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2487. return
  2488. }
  2489. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2490. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2491. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2492. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2493. if assessmentAfterDislysis != nil {
  2494. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2495. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2496. } else {
  2497. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2498. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2499. tempassessmentAfterDislysis.Status = 1
  2500. tempassessmentAfterDislysis.PatientId = id
  2501. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2502. }
  2503. //长沙南雅
  2504. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2505. //获取最后一条透析处方数据
  2506. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2507. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2508. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2509. }
  2510. if dialysisOrder.Stage == 1 {
  2511. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2512. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2513. fmt.Println(value)
  2514. a, b := math.Modf(value)
  2515. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2516. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2517. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2518. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2519. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2520. }
  2521. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2522. //var num1 int64
  2523. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2524. //fmt.Println(num1)
  2525. //sub := float64(num1 / 3600)
  2526. //fmt.Println(sub)
  2527. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2528. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2529. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2530. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2531. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2532. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2533. if adminUserInfo.Org.Id != 10375 {
  2534. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2535. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2536. }
  2537. if adminUserInfo.Org.Id != 10445 {
  2538. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2539. }
  2540. //北方营口医院
  2541. if adminUserInfo.Org.Id == 10445 {
  2542. //获取最后一条透析处方数据
  2543. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2544. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2545. } else {
  2546. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2547. }
  2548. //新化博翔
  2549. if adminUserInfo.Org.Id == 10447 {
  2550. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2551. }
  2552. //阳春
  2553. if adminUserInfo.Org.Id == 10485 {
  2554. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2555. }
  2556. if adminUserInfo.Org.Id == 10551 {
  2557. //获取最后一条透析处方数据
  2558. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2559. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2560. }
  2561. if adminUserInfo.Org.Id == 10580 {
  2562. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2563. }
  2564. if adminUserInfo.Org.Id == 10612 {
  2565. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2566. }
  2567. //孝康
  2568. if adminUserInfo.Org.Id == 10693 {
  2569. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2570. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2571. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2572. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2573. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2574. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2575. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2576. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2577. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2578. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2579. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2580. }
  2581. if adminUserInfo.Org.Id == 10721 {
  2582. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2583. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2584. }
  2585. if adminUserInfo.Org.Id == 10697 {
  2586. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2587. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2588. lastWeightAfter.LastAfterWeight = floatAfeter
  2589. }
  2590. }
  2591. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10693 || adminUserInfo.Org.Id == 10702 {
  2592. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2593. if adminUserInfo.Org.Id != 10702 {
  2594. if evaluation.SystolicBloodPressure == 0 {
  2595. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2596. if adminUserInfo.Org.Id == 10693 {
  2597. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2598. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2599. }
  2600. pre := models.PredialysisEvaluation{
  2601. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2602. }
  2603. fmt.Println("prew", pre)
  2604. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2605. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2606. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2607. redis := service.RedisClient()
  2608. redis.Set(key, "", time.Second)
  2609. redis.Set(keyOne, "", time.Second)
  2610. defer redis.Close()
  2611. fmt.Println(getNurseErr)
  2612. }
  2613. }
  2614. if adminUserInfo.Org.Id != 10702 {
  2615. if evaluation.DiastolicBloodPressure == 0 {
  2616. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2617. if adminUserInfo.Org.Id == 10693 {
  2618. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2619. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2620. }
  2621. pres := models.PredialysisEvaluation{
  2622. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2623. }
  2624. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2625. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2626. redis := service.RedisClient()
  2627. redis.Set(key, "", time.Second)
  2628. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2629. redis.Set(keyOne, "", time.Second)
  2630. defer redis.Close()
  2631. fmt.Println(getNurseErr)
  2632. }
  2633. }
  2634. if adminUserInfo.Org.Id != 10702 {
  2635. if evaluation.PulseFrequency == 0 {
  2636. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2637. if adminUserInfo.Org.Id == 10693 {
  2638. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2639. evaluation.PulseFrequency = pulseFrequency
  2640. }
  2641. press := models.PredialysisEvaluation{
  2642. PulseFrequency: evaluation.PulseFrequency,
  2643. }
  2644. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2645. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2646. redis := service.RedisClient()
  2647. redis.Set(key, "", time.Second)
  2648. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2649. redis.Set(keyOne, "", time.Second)
  2650. defer redis.Close()
  2651. fmt.Println(getNurseErr)
  2652. }
  2653. }
  2654. if evaluation.Temperature == 0 {
  2655. evaluation.Temperature = fmonitorRecords.Temperature
  2656. press := models.PredialysisEvaluation{
  2657. Temperature: evaluation.Temperature,
  2658. }
  2659. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2660. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2661. redis := service.RedisClient()
  2662. redis.Set(key, "", time.Second)
  2663. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2664. redis.Set(keyOne, "", time.Second)
  2665. defer redis.Close()
  2666. fmt.Println(getNurseErr)
  2667. }
  2668. }
  2669. if adminUserInfo.Org.Id == 9583 {
  2670. //获取透析处方的最后一条数据
  2671. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2672. if diaerr != nil {
  2673. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2675. return
  2676. }
  2677. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2678. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2679. }
  2680. }
  2681. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2682. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2683. }
  2684. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2685. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2686. }
  2687. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2688. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2689. }
  2690. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2691. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2692. }
  2693. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2694. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2695. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2696. }
  2697. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2698. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2699. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2700. }
  2701. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2702. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2703. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2704. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2705. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2706. }
  2707. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2708. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2709. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2710. }
  2711. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2712. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2713. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2714. }
  2715. if lastAssessmentAfterDislysis != nil {
  2716. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2717. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2718. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2719. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2720. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2721. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2722. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2723. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2724. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2725. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2726. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2727. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2728. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2729. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2730. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2731. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2732. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2733. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2734. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2735. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2736. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2737. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2738. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2739. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2740. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2741. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2742. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2743. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2744. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2745. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2746. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2747. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2748. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2749. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2750. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2751. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2752. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2753. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2754. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2755. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2756. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2757. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2758. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2759. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2760. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2761. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2762. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2763. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2764. if tempassessmentAfterDislysis.PatientId == 18695 {
  2765. tempassessmentAfterDislysis.ActualDisplacement = 0
  2766. }
  2767. if adminUserInfo.Org.Id != 10375 {
  2768. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2769. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2770. }
  2771. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2772. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2773. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2774. }
  2775. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2776. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2777. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2778. }
  2779. }
  2780. finish := models.XtDialysisFinish{
  2781. IsFinish: 1,
  2782. UserOrgId: adminUserInfo.Org.Id,
  2783. Status: 1,
  2784. Ctime: time.Now().Unix(),
  2785. Mtime: 0,
  2786. Module: 9,
  2787. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2788. Sourse: 1,
  2789. PatientId: tempassessmentAfterDislysis.PatientId,
  2790. }
  2791. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2792. if dialysisFinish.ID == 0 {
  2793. service.CreateDialysisFinish(finish)
  2794. }
  2795. //孝康
  2796. if adminUserInfo.Org.Id == 10693 {
  2797. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2798. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2799. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2800. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2801. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2802. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2803. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2804. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2805. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2806. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2807. }
  2808. if adminUserInfo.Org.Id == 10697 {
  2809. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2810. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2811. lastWeightAfter.LastAfterWeight = floatAfeter
  2812. }
  2813. if adminUserInfo.Org.Id == 10721 {
  2814. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2815. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2816. }
  2817. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2818. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2819. redis := service.RedisClient()
  2820. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2821. redis.Set(keyOne, "", time.Second)
  2822. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2823. redis.Set(keyTwo, "", time.Second)
  2824. defer redis.Close()
  2825. //清空key 值
  2826. redis.Set(key, "", time.Second)
  2827. if err != nil {
  2828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2829. return
  2830. }
  2831. if dialysisOrder == nil {
  2832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2833. return
  2834. }
  2835. if dialysisOrder.Stage == 2 {
  2836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2837. return
  2838. }
  2839. if dialysisOrder.Stage == 1 {
  2840. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2841. finish := models.XtDialysisFinish{
  2842. IsFinish: 1,
  2843. UserOrgId: adminUserInfo.Org.Id,
  2844. Status: 1,
  2845. Ctime: time.Now().Unix(),
  2846. Mtime: 0,
  2847. Module: 8,
  2848. RecordDate: recordDate.Unix(),
  2849. Sourse: 1,
  2850. PatientId: id,
  2851. }
  2852. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2853. if dialysisFinish.ID == 0 {
  2854. service.CreateDialysisFinish(finish)
  2855. }
  2856. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2857. redis := service.RedisClient()
  2858. defer redis.Close()
  2859. //清空key 值
  2860. redis.Set(key, "", time.Second)
  2861. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2862. redis.Set(keyOne, "", time.Second)
  2863. //结束时候透析次数加1
  2864. service.UpdateSolutionByPatientId(id)
  2865. //下机完自动消毒,针对长沙南雅
  2866. if dialysisOrder.Stage == 1 {
  2867. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2868. //根据床位号获取设备型号
  2869. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2870. //查询使用消毒最后一条消毒记录
  2871. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2872. fmt.Println("err", err)
  2873. if err == gorm.ErrRecordNotFound {
  2874. //查找排班
  2875. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2876. //查询改设备是否有消毒计划
  2877. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2878. //根据床位号获取设备id
  2879. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2880. //查询病人信息
  2881. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2882. var con = ""
  2883. if patients.IsInfectious == 0 {
  2884. con = ""
  2885. }
  2886. if patients.IsInfectious == 1 {
  2887. con = "无"
  2888. }
  2889. if patients.IsInfectious == 2 {
  2890. con = "有"
  2891. }
  2892. if errcode == nil {
  2893. var end_time int64
  2894. end_time = endDate.Unix() + plan.DisinfecTime*60
  2895. //新增消毒
  2896. information := models.DeviceInformation{
  2897. Date: dialysisOrder.DialysisDate,
  2898. Zone: dialysisOrder.ZoneId,
  2899. Class: dialysisOrder.SchedualType,
  2900. BedNumber: dialysisOrder.BedID,
  2901. PatientId: dialysisOrder.PatientId,
  2902. DialysisMode: scheduleByPatient.ModeId,
  2903. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2904. Disinfection: 1,
  2905. DialysisConcentration: 1,
  2906. DisinfectionStatus: 1,
  2907. Move: 1,
  2908. UserOrgId: dialysisOrder.UserOrgId,
  2909. DisinfectType: plan.Way,
  2910. DisinfectantType: plan.MachineDisinfectant,
  2911. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2912. Disinfectant: plan.Disinfectant,
  2913. Ctime: time.Now().Unix(),
  2914. Status: 1,
  2915. SignName: nurseID,
  2916. EquimentId: addmacher.ID,
  2917. DisinfectionResidue: 2,
  2918. Bed: addmacher.BedNumber,
  2919. StartTime: dialysisOrder.StartTime,
  2920. EndTime: dialysisOrder.EndTime,
  2921. Contagion: con,
  2922. WeightLoss: 0,
  2923. Hyperfiltratio: 0,
  2924. DialysisHour: "",
  2925. MachineRun: 1,
  2926. DisinfecStartime: endDate.Unix(),
  2927. DisinfecEndtime: end_time,
  2928. }
  2929. err := service.CreateInformationTwo(&information)
  2930. fmt.Println("报错", err)
  2931. }
  2932. }
  2933. }
  2934. }
  2935. dialysisOrder.Stage = 2
  2936. dialysisOrder.FinishNurse = nurseID
  2937. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2938. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2939. dialysisOrder.EndTime = endDate.Unix()
  2940. // 长沙南雅需求
  2941. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2942. //获取最后1条监测的数据
  2943. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2944. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2945. var accumulatedBloodVolume float64
  2946. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2947. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2948. fmt.Println(err)
  2949. // 查询未执行的医嘱
  2950. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2951. for _, item := range doctorAdvice {
  2952. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2953. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2954. redis := service.RedisClient()
  2955. //清空key 值
  2956. redis.Set(key, "", time.Second)
  2957. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2958. redis.Set(keyTwo, "", time.Second)
  2959. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2960. redis.Set(keyThree, "", time.Second)
  2961. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2962. theTime := toTime.Format("2006-01-02")
  2963. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2964. redis.Set(keyFour, "", time.Second)
  2965. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2966. redis.Set(keyFive, "", time.Second)
  2967. defer redis.Close()
  2968. }
  2969. }
  2970. go func() {
  2971. ssoDomain := beego.AppConfig.String("call_domain")
  2972. api := ssoDomain + "/index/downpatient"
  2973. values := make(url.Values)
  2974. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2975. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2976. values.Set("patient_id", strconv.FormatInt(id, 10))
  2977. http.PostForm(api, values)
  2978. }()
  2979. if err == nil {
  2980. c.ServeSuccessJSON(map[string]interface{}{
  2981. "dialysisOrder": dialysisOrder,
  2982. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2983. })
  2984. } else {
  2985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2986. }
  2987. }
  2988. }
  2989. func (c *DialysisAPIController) GetAllZone() {
  2990. adminUserInfo := c.GetMobileAdminUserInfo()
  2991. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2992. if err == nil {
  2993. c.ServeSuccessJSON(map[string]interface{}{
  2994. "zone": zone,
  2995. })
  2996. }
  2997. }
  2998. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2999. adminUserInfo := c.GetMobileAdminUserInfo()
  3000. page, _ := c.GetInt64("page", 1)
  3001. limit, _ := c.GetInt64("limit", 10)
  3002. schedulType, _ := c.GetInt64("schedul_type", 0)
  3003. startTime, _ := c.GetInt64("schedul_time", 0)
  3004. partitionType, _ := c.GetInt64("partition_type", 0)
  3005. keywords := c.GetString("keywords")
  3006. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3007. if err == nil {
  3008. c.ServeSuccessJSON(map[string]interface{}{
  3009. "schedule": dialysisSchedule,
  3010. })
  3011. }
  3012. return
  3013. }
  3014. // /m/api/dialysis/start [post]
  3015. // @param patient_id:int
  3016. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3017. // @param nurse:int 上机护士
  3018. // @param bed:int 床位号
  3019. func (this *DialysisAPIController) StartDialysis() {
  3020. patientID, _ := this.GetInt64("patient_id")
  3021. recordDateStr := this.GetString("record_date")
  3022. nurseID, _ := this.GetInt64("start_nurse")
  3023. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3024. blood_drawing, _ := this.GetInt64("blood_drawing")
  3025. schedual_type, _ := this.GetInt64("schedual_type")
  3026. bedID, _ := this.GetInt64("bed")
  3027. start_time := this.GetString("start_time")
  3028. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3029. change_nurse, _ := this.GetInt64("change_nurse")
  3030. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3031. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3032. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3033. puncture_needle := this.GetString("puncture_needle")
  3034. puncture_way := this.GetString("puncture_way")
  3035. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3036. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3037. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3038. zone_id, _ := this.GetInt64("zone_id")
  3039. elecsign := this.GetString("url")
  3040. nuclein_date_str := this.GetString("nuclein_date_str")
  3041. schedule_remark := this.GetString("schedule_remark")
  3042. order_remark := this.GetString("order_remark")
  3043. catheter_operation := this.GetString("catheter_operation")
  3044. blood_flow_volume := this.GetString("blood_flow_volume")
  3045. dialysis_strainer := this.GetString("dialysis_strainer")
  3046. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3047. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3048. return
  3049. }
  3050. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3051. if parseStartDateErr != nil {
  3052. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3053. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3054. return
  3055. }
  3056. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3057. if parseErr != nil {
  3058. this.ErrorLog("时间解析失败:%v", parseErr)
  3059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3060. return
  3061. }
  3062. adminUserInfo := this.GetMobileAdminUserInfo()
  3063. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3064. if getPatientErr != nil {
  3065. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3066. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3067. return
  3068. } else if patient == nil {
  3069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3070. return
  3071. }
  3072. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3073. if getNurseErr != nil {
  3074. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3075. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3076. return
  3077. } else if nurse == nil {
  3078. this.ErrorLog("护士不存在")
  3079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3080. return
  3081. }
  3082. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3083. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3084. if getDeviceNumberErr != nil {
  3085. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3086. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3087. return
  3088. } else if deviceNumber == nil {
  3089. this.ErrorLog("床位号不存在")
  3090. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3091. return
  3092. }
  3093. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3094. if getRecordErr != nil {
  3095. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3096. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3097. return
  3098. } else if dialysisRecord != nil {
  3099. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3100. return
  3101. }
  3102. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3103. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3104. timeLayout := "2006-01-02 15:04:05"
  3105. loc, _ := time.LoadLocation("Local")
  3106. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3107. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3108. schedulestartTime := theStartTime.Unix()
  3109. scheduleendTime := theEndTime.Unix()
  3110. var theNucleinDate int64
  3111. timeLayoutOne := "2006-01-02"
  3112. if len(nuclein_date_str) > 0 {
  3113. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3114. if err != nil {
  3115. utils.ErrorLog(err.Error())
  3116. }
  3117. theNucleinDate = theTime.Unix()
  3118. }
  3119. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3120. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3121. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3122. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3123. //查询该床位是否有人用了
  3124. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3125. if err == gorm.ErrRecordNotFound { //空床位
  3126. // 修改了床位逻辑
  3127. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3128. if daySchedule.ID > 0 {
  3129. daySchedule.PartitionId = deviceNumber.ZoneID
  3130. daySchedule.BedId = bedID
  3131. daySchedule.ScheduleType = schedual_type
  3132. daySchedule.UpdatedTime = time.Now().Unix()
  3133. xtSchedule := models.Schedule{
  3134. PartitionId: deviceNumber.ZoneID,
  3135. BedId: bedID,
  3136. ScheduleType: schedual_type,
  3137. UpdatedTime: time.Now().Unix(),
  3138. }
  3139. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3140. if err != nil {
  3141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3142. return
  3143. }
  3144. }
  3145. } else if err == nil {
  3146. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3147. if order.ID > 0 { //该机位被其他人占用了
  3148. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3149. return
  3150. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3151. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3152. if daySchedule.ID > 0 {
  3153. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3154. if err != nil {
  3155. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3156. return
  3157. }
  3158. }
  3159. }
  3160. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3162. return
  3163. }
  3164. //else if order.ID == 0 { //该床位没被占用
  3165. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3166. // if daySchedule.ID > 0 {
  3167. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3168. // //daySchedule.BedId = bedID
  3169. // //daySchedule.ScheduleType = schedual_type
  3170. // //daySchedule.UpdatedTime = time.Now().Unix()
  3171. // //err := service.UpdateSchedule(&daySchedule)
  3172. // xtSchedule := models.Schedule{
  3173. // PartitionId: deviceNumber.ZoneID,
  3174. // BedId: bedID,
  3175. // ScheduleType: schedual_type,
  3176. // UpdatedTime: time.Now().Unix(),
  3177. // }
  3178. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3179. // if err != nil {
  3180. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3181. // return
  3182. // }
  3183. // }
  3184. //}
  3185. //}
  3186. } else if err != nil {
  3187. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3188. return
  3189. }
  3190. // 查询信息规挡的设置天数
  3191. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3192. if infor.ID > 0 && infor.WeekDay > 0 {
  3193. var cha_time int64
  3194. timeNowStr := time.Now().Format("2006-01-02")
  3195. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3196. //今日的日期减去设置的日期
  3197. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3198. if cha_time >= recordDate.Unix() {
  3199. //查询审核是否允许
  3200. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3201. //申请状态不允许的情况 拒绝修改
  3202. if infor.ApplicationStatus != 1 {
  3203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3204. return
  3205. }
  3206. }
  3207. }
  3208. dialysisRecord = &models.DialysisOrder{
  3209. DialysisDate: recordDate.Unix(),
  3210. UserOrgId: adminUserInfo.Org.Id,
  3211. PatientId: patientID,
  3212. Stage: 1,
  3213. BedID: bedID,
  3214. StartNurse: nurseID,
  3215. Status: 1,
  3216. StartTime: startDate.Unix(),
  3217. CreatedTime: time.Now().Unix(),
  3218. UpdatedTime: time.Now().Unix(),
  3219. PunctureNurse: puncture_nurse,
  3220. Creator: adminUserInfo.AdminUser.Id,
  3221. Modifier: adminUserInfo.AdminUser.Id,
  3222. SchedualType: schedual_type,
  3223. WashpipeNurse: washpipe_nurse,
  3224. ChangeNurse: change_nurse,
  3225. DifficultPunctureNurse: difficult_puncture_nurse,
  3226. NewFistulaNurse: new_fistula_nurse,
  3227. ZoneId: zone_id,
  3228. QualityNurseId: quality_nurse_id,
  3229. PunctureNeedle: puncture_needle,
  3230. PunctureWay: puncture_way,
  3231. DialysisIrrigation: dialysis_irrigation,
  3232. DialysisDialyszers: dialysis_dialyszers,
  3233. BloodAccessId: blood_access_id,
  3234. Url: elecsign,
  3235. NucleinDate: theNucleinDate,
  3236. ScheduleRemark: schedule_remark,
  3237. OrderRemark: order_remark,
  3238. CatheterOperation: catheter_operation,
  3239. BloodFlowVolume: blood_flow_volume,
  3240. BloodDrawing: blood_drawing,
  3241. DialysisStrainer: dialysis_strainer,
  3242. }
  3243. //查询该床位是否有人用了
  3244. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3245. if errorscode == gorm.ErrRecordNotFound {
  3246. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3247. finish := models.XtDialysisFinish{
  3248. IsFinish: 1,
  3249. UserOrgId: adminUserInfo.Org.Id,
  3250. Status: 1,
  3251. Ctime: time.Now().Unix(),
  3252. Mtime: 0,
  3253. Module: 6,
  3254. RecordDate: schedulestartTime,
  3255. Sourse: 1,
  3256. PatientId: patientID,
  3257. }
  3258. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3259. if dialysisFinish.ID == 0 {
  3260. service.CreateDialysisFinish(finish)
  3261. }
  3262. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3263. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3264. //统计该患者总次数
  3265. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3266. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3267. }
  3268. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3269. //统计该患者总次数
  3270. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3271. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3272. }
  3273. redis := service.RedisClient()
  3274. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3275. redis.Set(key, "", time.Second)
  3276. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3277. //清空key 值
  3278. redis.Set(keyOne, "", time.Second)
  3279. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3280. //清空key 值
  3281. redis.Set(keyTwo, "", time.Second)
  3282. if createErr != nil {
  3283. this.ErrorLog("上机失败:%v", createErr)
  3284. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3285. return
  3286. }
  3287. }
  3288. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3289. var tempdispose string
  3290. // 只针对中能建
  3291. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3292. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3293. }
  3294. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3295. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3296. }
  3297. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3298. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3299. //}
  3300. var ultrafiltration_rate float64
  3301. var ultrafiltration_rate_one string
  3302. var replacement_rate float64
  3303. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3304. //后期预增脱水量
  3305. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3306. if prescription.ID > 0 {
  3307. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3308. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3309. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  3310. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3311. }
  3312. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3313. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3314. }
  3315. //针对医师汇
  3316. if adminUserInfo.Org.Id == 10121 {
  3317. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3318. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3319. }
  3320. //针对通道
  3321. if adminUserInfo.Org.Id == 10234 {
  3322. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3323. }
  3324. //针对监利大垸医院
  3325. if template.TemplateId == 41 {
  3326. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3327. }
  3328. //针对肇庆三鹤血液透析中心
  3329. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3330. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3331. }
  3332. if adminUserInfo.Org.Id == 10469 {
  3333. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3334. }
  3335. if adminUserInfo.Org.Id == 10667 {
  3336. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3337. }
  3338. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3339. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3340. }
  3341. // 只针对方济医院
  3342. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3343. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3344. ultrafiltration_rate = value
  3345. }
  3346. //针对
  3347. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3348. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3349. ultrafiltration_rate = ultrafiltration_rate / 1000
  3350. }
  3351. if adminUserInfo.Org.Id == 10551 {
  3352. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3353. ultrafiltration_rate = ultrafiltration_rate / 1000
  3354. }
  3355. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3356. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3357. ultrafiltration_rate = ultrafiltration_rate / 1000
  3358. }
  3359. if adminUserInfo.Org.Id == 10580 {
  3360. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3361. ultrafiltration_rate = ultrafiltration_rate / 1000
  3362. }
  3363. if adminUserInfo.Org.Id == 10629 {
  3364. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3365. ultrafiltration_rate = ultrafiltration_rate / 1000
  3366. }
  3367. if adminUserInfo.Org.Id == 10644 {
  3368. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3369. ultrafiltration_rate = ultrafiltration_rate / 1000
  3370. }
  3371. if adminUserInfo.Org.Id == 10667 {
  3372. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3373. ultrafiltration_rate = ultrafiltration_rate / 1000
  3374. }
  3375. if adminUserInfo.Org.Id == 10693 {
  3376. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3377. ultrafiltration_rate = ultrafiltration_rate
  3378. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3379. }
  3380. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3381. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3382. ultrafiltration_rate = ultrafiltration_rate
  3383. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3384. }
  3385. if adminUserInfo.Org.Id == 10206 {
  3386. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3387. ultrafiltration_rate = ultrafiltration_rate
  3388. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3389. }
  3390. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3391. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3392. ultrafiltration_rate = ultrafiltration_rate
  3393. }
  3394. if adminUserInfo.Org.Id == 10702 {
  3395. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3396. ultrafiltration_rate = ultrafiltration_rate / 1000
  3397. }
  3398. if adminUserInfo.Org.Id == 10723 {
  3399. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3400. ultrafiltration_rate = ultrafiltration_rate / 1000
  3401. }
  3402. if adminUserInfo.Org.Id == 10721 {
  3403. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3404. ultrafiltration_rate = ultrafiltration_rate / 1000
  3405. }
  3406. if adminUserInfo.Org.Id == 10721 {
  3407. if prescription.ModeId == 2 {
  3408. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3409. if totalMin == 0 {
  3410. totalMin = 240
  3411. }
  3412. if prescription.ReplacementTotal == 0 {
  3413. prescription.ReplacementTotal = 15
  3414. }
  3415. //乘10 除10是为了保留一位小数
  3416. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3417. }
  3418. }
  3419. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 {
  3420. if prescription.ModeId == 2 {
  3421. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3422. if totalMin == 0 {
  3423. totalMin = 240
  3424. }
  3425. if prescription.DisplaceLiquiValue == 0 {
  3426. prescription.ReplacementTotal = 32
  3427. }
  3428. //乘10 除10是为了保留一位小数
  3429. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3430. }
  3431. }
  3432. }
  3433. }
  3434. if adminUserInfo.Org.Id == 10172 {
  3435. if prescription.ID == 0 {
  3436. if prescription.ModeId == 2 {
  3437. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3438. if totalMin == 0 {
  3439. totalMin = 240
  3440. }
  3441. if prescription.ReplacementTotal == 0 {
  3442. prescription.ReplacementTotal = 15
  3443. }
  3444. //乘10 除10是为了保留一位小数
  3445. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3446. }
  3447. }
  3448. }
  3449. record := models.MonitoringRecord{
  3450. UserOrgId: adminUserInfo.Org.Id,
  3451. PatientId: patientID,
  3452. DialysisOrderId: dialysisRecord.ID,
  3453. MonitoringDate: schedulestartTime,
  3454. OperateTime: startDate.Unix(),
  3455. // MonitoringTime: recordTime,
  3456. MonitoringNurse: nurseID,
  3457. Dispose: tempdispose,
  3458. UltrafiltrationRate: ultrafiltration_rate,
  3459. UltrafiltrationVolume: 0,
  3460. Status: 1,
  3461. CreatedTime: time.Now().Unix(),
  3462. UpdatedTime: time.Now().Unix(),
  3463. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3464. ReplacementRate: replacement_rate,
  3465. }
  3466. //只针对广慈医院
  3467. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10517 || adminUserInfo.Org.Id == 10679 {
  3468. // 查询病人是否有透前评估数据
  3469. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3470. //如果有数据就插入
  3471. if errcode == nil {
  3472. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3473. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3474. record.BreathingRate = befor.BreathingRate
  3475. record.PulseFrequency = befor.PulseFrequency
  3476. record.Temperature = befor.Temperature
  3477. }
  3478. }
  3479. //孝昌
  3480. if adminUserInfo.Org.Id == 10693 {
  3481. // 查询病人是否有透前评估数据
  3482. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3483. //如果有数据就插入
  3484. if errcode == nil {
  3485. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3486. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3487. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3488. record.BreathingRate = befor.BreathingRate
  3489. }
  3490. }
  3491. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3492. if newdialysisRecord.ID > 0 {
  3493. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3494. record.Temperature = 36.5
  3495. record.ArterialPressure = -100
  3496. record.DialysateTemperature = 36.5
  3497. record.Conductivity = 14
  3498. record.BreathingRate = "20"
  3499. record.VenousPressure = 80
  3500. record.TransmembranePressure = 60
  3501. record.Dispose = catheter_operation
  3502. }
  3503. //针对新化博翔
  3504. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3505. record.BloodOxygenSaturation = "99"
  3506. record.Conductivity = 14
  3507. record.DialysateTemperature = 36.5
  3508. record.BreathingRate = "20"
  3509. }
  3510. //针对兰溪人民医院的需求
  3511. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3512. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3513. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3514. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3515. record.Temperature = befor.Temperature
  3516. record.PulseFrequency = befor.PulseFrequency
  3517. record.BreathingRate = befor.BreathingRate
  3518. }
  3519. //针对乐山友谊医院的需求
  3520. if adminUserInfo.Org.Id == 10677 {
  3521. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3522. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3523. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3524. record.Temperature = befor.Temperature
  3525. record.PulseFrequency = befor.PulseFrequency
  3526. record.BreathingRate = befor.BreathingRate
  3527. }
  3528. //新化博翔
  3529. if adminUserInfo.Org.Id == 10447 {
  3530. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3531. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3532. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3533. record.BreathingRate = befor.BreathingRate
  3534. }
  3535. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3536. record.PulseFrequency = 80
  3537. record.Temperature = 36.5
  3538. }
  3539. //诊断灵山圣康
  3540. if adminUserInfo.Org.Id == 10375 {
  3541. record.Conductivity = 13.8
  3542. record.DialysateTemperature = 37
  3543. record.DialysateFlow = 500
  3544. record.BloodFlowVolume = 200
  3545. record.BreathingRate = "18"
  3546. record.SodiumConcentration = 140
  3547. }
  3548. //江成肾病医院
  3549. if adminUserInfo.Org.Id == 10517 {
  3550. record.SodiumConcentration = 138
  3551. record.DialysateTemperature = 36.5
  3552. }
  3553. //濉溪杏康血液透析中心
  3554. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3555. record.BloodFlowVolume = prescription.BloodFlowVolume
  3556. }
  3557. if adminUserInfo.Org.Id != 10683 {
  3558. err = service.CreateMonitor(&record)
  3559. }
  3560. //记录日志
  3561. byterequest, _ := json.Marshal(record)
  3562. monitorRecordLog := models.XtMonitorRecordLog{
  3563. RecordDate: record.MonitoringDate,
  3564. PatientId: record.PatientId,
  3565. Module: 1,
  3566. AdminUserId: adminUserInfo.AdminUser.Id,
  3567. Ctime: time.Now().Unix(),
  3568. Mtime: 0,
  3569. Status: 1,
  3570. UserOrgId: record.UserOrgId,
  3571. ErrLog: string(byterequest),
  3572. Source: "执行上机时新增监测",
  3573. }
  3574. service.CreateMonitorRecordLog(monitorRecordLog)
  3575. finish := models.XtDialysisFinish{
  3576. IsFinish: 1,
  3577. UserOrgId: adminUserInfo.Org.Id,
  3578. Status: 1,
  3579. Ctime: time.Now().Unix(),
  3580. Mtime: 0,
  3581. Module: 7,
  3582. RecordDate: schedulestartTime,
  3583. Sourse: 1,
  3584. PatientId: patientID,
  3585. }
  3586. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3587. if dialysisFinish.ID == 0 {
  3588. service.CreateDialysisFinish(finish)
  3589. }
  3590. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3591. redis := service.RedisClient()
  3592. //清空key 值
  3593. redis.Set(key, "", time.Second)
  3594. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3595. redis.Set(keyOne, "", time.Second)
  3596. defer redis.Close()
  3597. if err != nil {
  3598. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3599. return
  3600. }
  3601. }
  3602. go func() {
  3603. ssoDomain := beego.AppConfig.String("call_domain")
  3604. api := ssoDomain + "/index/uppatient"
  3605. values := make(url.Values)
  3606. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3607. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3608. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3609. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3610. http.PostForm(api, values)
  3611. }()
  3612. this.ServeSuccessJSON(map[string]interface{}{
  3613. "dialysis_order": newdialysisRecord,
  3614. "monitor": record,
  3615. })
  3616. return
  3617. }
  3618. func (c *DialysisAPIController) PostSolution() {
  3619. id, _ := c.GetInt64("patient", 0)
  3620. recordDateStr := c.GetString("record_date")
  3621. if id <= 0 {
  3622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3623. return
  3624. }
  3625. adminUserInfo := c.GetMobileAdminUserInfo()
  3626. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3627. if patient.ID == 0 {
  3628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3629. return
  3630. }
  3631. if len(recordDateStr) == 0 {
  3632. recordDateStr = time.Now().Format("2006-01-02")
  3633. }
  3634. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3635. if parseDateErr != nil {
  3636. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3638. return
  3639. }
  3640. mode_id, _ := c.GetInt64("mode_id", 0)
  3641. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3642. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3643. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3644. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3645. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3646. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3647. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3648. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3649. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3650. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3651. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3652. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3653. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3654. kalium, _ := c.GetFloat("kalium", 0)
  3655. sodium, _ := c.GetFloat("sodium", 0)
  3656. calcium, _ := c.GetFloat("calcium", 0)
  3657. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3658. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3659. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3660. glucose, _ := c.GetFloat("glucose", 0)
  3661. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3662. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3663. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3664. conductivity, _ := c.GetFloat("conductivity", 0)
  3665. remark := c.GetString("remark")
  3666. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3667. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3668. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3669. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3670. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3671. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3672. special_medicine_other := c.GetString("special_medicine_other")
  3673. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3674. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3675. blood_access, _ := c.GetInt64("blood_access", 0)
  3676. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3677. body_fluid_other := c.GetString("body_fluid_other")
  3678. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3679. niprocart, _ := c.GetInt64("niprocart", 0)
  3680. jms, _ := c.GetInt64("jms", 0)
  3681. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3682. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3683. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3684. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3685. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3686. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3687. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3688. injector, _ := c.GetInt64("injector", 0)
  3689. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3690. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3691. safe_package, _ := c.GetInt64("package", 0)
  3692. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3693. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3694. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3695. blood := c.GetString("blood")
  3696. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3697. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3698. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3699. displace_speed := c.GetString("displace_speed")
  3700. illness, _ := c.GetInt64("illness")
  3701. amylaceum := c.GetString("amylaceum")
  3702. single_time := c.GetString("single_time")
  3703. single_water := c.GetString("single_water")
  3704. replacement_flow := c.GetString("replacement_flow")
  3705. plasma_separator := c.GetString("plasma_separator")
  3706. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3707. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3708. oxygen_flow := c.GetString("oxygen_flow")
  3709. oxygen_time := c.GetString("oxygen_time")
  3710. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3711. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3712. puncture_needle := c.GetString("puncture_needle")
  3713. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3714. epo := c.GetString("epo")
  3715. epo_count, _ := c.GetFloat("epo_count", 0)
  3716. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3717. pre_impulse := c.GetString("pre_impulse")
  3718. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3719. admin_user_id, _ := c.GetInt64("admin_user_id")
  3720. is_water := c.GetString("is_water")
  3721. add_amount, _ := c.GetFloat("add_amount")
  3722. reduce_amount, _ := c.GetFloat("reduce_amount")
  3723. prescribing_number, _ := c.GetFloat("prescribing_number")
  3724. treatment_remark := c.GetString("treatment_remark")
  3725. prescription_sodium := c.GetString("prescription_sodium")
  3726. start_sodium := c.GetString("start_sodium")
  3727. sodium_curve := c.GetString("sodium_curve")
  3728. var is_war int64
  3729. if is_water == "是" {
  3730. is_war = 1
  3731. }
  3732. if is_water == "否" {
  3733. is_war = 2
  3734. }
  3735. if is_water == "请选择" {
  3736. is_war = 0
  3737. }
  3738. drhy_water := c.GetString("drhy_water")
  3739. dry_water_hour := c.GetString("dry_water_hour")
  3740. water_machine := c.GetString("water_machine")
  3741. dialysis_remark := c.GetString("dialysis_remark")
  3742. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3743. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3744. prescription_water, _ := c.GetFloat("prescription_water")
  3745. dialysis_strainer := c.GetString("dialysis_strainer")
  3746. chaptalization := c.GetString("chaptalization")
  3747. washing_time := c.GetString("washing_time")
  3748. warsh_count := c.GetString("warsh_count")
  3749. blood_access_part_id := c.GetString("blood_access_part_id")
  3750. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3751. dialyzate := c.GetString("dialyzate")
  3752. first_super := c.GetString("first_super")
  3753. is_sequential := c.GetString("is_sequential")
  3754. var fisrt_sup int64
  3755. if first_super == "是" {
  3756. fisrt_sup = 1
  3757. }
  3758. if first_super == "否" {
  3759. fisrt_sup = 2
  3760. }
  3761. if first_super == "请选择" {
  3762. fisrt_sup = 0
  3763. }
  3764. var is_sequen int64
  3765. if is_sequential == "是" {
  3766. is_sequen = 1
  3767. }
  3768. if is_sequential == "否" {
  3769. is_sequen = 2
  3770. }
  3771. if is_sequential == "请选择" {
  3772. is_sequen = 0
  3773. }
  3774. conduct := c.GetString("conduct")
  3775. if mode_id > 0 {
  3776. var str string
  3777. //查找该机构用的是什么透析器
  3778. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3779. if filedConfig.ID > 0 {
  3780. str = dialyzerPerfusionApparatus
  3781. } else {
  3782. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3783. }
  3784. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3785. }
  3786. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3787. //
  3788. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3789. // if appRole.UserType == 3 {
  3790. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3791. // if getPermissionErr != nil {
  3792. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3793. // return
  3794. // } else if headNursePermission == nil {
  3795. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3796. // return
  3797. // }
  3798. // }
  3799. //}
  3800. // 查询信息规挡的设置天数
  3801. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3802. if infor.ID > 0 && infor.WeekDay > 0 {
  3803. var cha_time int64
  3804. timeNowStr := time.Now().Format("2006-01-02")
  3805. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3806. //今日的日期减去设置的日期
  3807. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3808. if cha_time >= recordDate.Unix() {
  3809. //查询审核是否允许
  3810. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3811. //申请状态不允许的情况 拒绝修改
  3812. if infor.ApplicationStatus != 1 {
  3813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3814. return
  3815. }
  3816. }
  3817. }
  3818. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  3819. var dialysis_dialyszers_id int64
  3820. var dialysis_strainer_id int64
  3821. var dialysis_irrigation_id int64
  3822. if len(goodList) > 0 {
  3823. for _, item := range goodList {
  3824. if item.SpecificationName == dialysis_dialyszers {
  3825. dialysis_dialyszers_id = item.ID
  3826. }
  3827. if item.SpecificationName == dialysis_irrigation {
  3828. dialysis_irrigation_id = item.ID
  3829. }
  3830. if item.SpecificationName == dialysis_strainer {
  3831. dialysis_strainer_id = item.ID
  3832. }
  3833. }
  3834. }
  3835. prescription := models.DialysisPrescription{
  3836. UserOrgId: adminUserInfo.Org.Id,
  3837. PatientId: id,
  3838. RecordDate: recordDate.Unix(),
  3839. ModeId: mode_id,
  3840. DialysisDuration: dialysis_duration,
  3841. Dialyzer: dialyzer,
  3842. PerfusionApparatus: perfusion_apparatus,
  3843. BloodFlowVolume: blood_flow_volume,
  3844. DewaterAmount: dewater_amount,
  3845. DisplaceLiqui: displace_liqui,
  3846. ReplacementWay: replacement_way,
  3847. Anticoagulant: anticoagulant,
  3848. AnticoagulantShouji: anticoagulant_shouji,
  3849. AnticoagulantWeichi: anticoagulant_weichi,
  3850. AnticoagulantZongliang: anticoagulant_zongliang,
  3851. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3852. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3853. Kalium: kalium,
  3854. Sodium: sodium,
  3855. Calcium: calcium,
  3856. Bicarbonate: bicarbonate,
  3857. Glucose: glucose,
  3858. // DryWeight: dry_weight,
  3859. DialysateFlow: dialysate_flow,
  3860. DialysateTemperature: dialysate_temperature,
  3861. Conductivity: conductivity,
  3862. Remark: remark,
  3863. Status: 1,
  3864. CreatedTime: time.Now().Unix(),
  3865. UpdatedTime: time.Now().Unix(),
  3866. DialysisDurationMinute: dialysisDurationMinute,
  3867. DialysisDurationHour: dialysisDurationHour,
  3868. TargetUltrafiltration: targetUltrafiltration,
  3869. DialysateFormulation: dialysateFormulation,
  3870. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3871. BodyFluid: body_fluid,
  3872. SpecialMedicine: special_medicine,
  3873. SpecialMedicineOther: special_medicine_other,
  3874. DisplaceLiquiPart: displace_liqui_part,
  3875. DisplaceLiquiValue: displace_liqui_value,
  3876. BloodAccess: blood_access,
  3877. Ultrafiltration: ultrafiltration,
  3878. BodyFluidOther: body_fluid_other,
  3879. ReplacementTotal: replacement_total,
  3880. Niprocart: niprocart,
  3881. Jms: jms,
  3882. FistulaNeedleSet: fistula_needle_set,
  3883. FistulaNeedleSet16: fistula_needle_set_16,
  3884. Hemoperfusion: hemoperfusion,
  3885. DialyserSterilised: dialyser_sterilised,
  3886. Filtryzer: filtryzer,
  3887. TargetKtv: target_ktv,
  3888. Dialyzers: dialyzers,
  3889. Injector: injector,
  3890. Bloodlines: bloodlines,
  3891. TubingHemodialysis: tubing_hemodialysis,
  3892. Package: safe_package,
  3893. ALiquid: a_liquid,
  3894. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3895. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3896. Blood: blood,
  3897. DialysisDialyszers: dialysis_dialyszers,
  3898. DialysisIrrigation: dialysis_irrigation,
  3899. AntioxidantCommodityName: antioxidant_commodity_name,
  3900. DisplaceSpeed: displace_speed,
  3901. Illness: illness,
  3902. Amylaceum: amylaceum,
  3903. SingleWater: single_water,
  3904. SingleTime: single_time,
  3905. ReplacementFlow: replacement_flow,
  3906. PlasmaSeparator: plasma_separator,
  3907. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3908. OxygenUptake: oxygen_uptake,
  3909. OxygenTime: oxygen_time,
  3910. OxygenFlow: oxygen_flow,
  3911. HemodialysisPipelines: hemodialysis_pipelines,
  3912. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3913. PunctureNeedle: puncture_needle,
  3914. PunctureNeedleCount: puncture_needle_count,
  3915. Epo: epo,
  3916. EpoCount: epo_count,
  3917. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3918. PreImpulse: impulse,
  3919. AdminUserId: admin_user_id,
  3920. IsWater: is_war,
  3921. DrhyWater: drhy_water,
  3922. DryWaterHour: dry_water_hour,
  3923. WaterMachine: water_machine,
  3924. AddAmount: add_amount,
  3925. ReduceAmount: reduce_amount,
  3926. DialysisRemark: dialysis_remark,
  3927. PrescribingNumber: prescribing_number,
  3928. PrescriptionSodium: prescription_sodium,
  3929. StartSodium: start_sodium,
  3930. SodiumCurve: sodium_curve,
  3931. TreatmentRemark: treatment_remark,
  3932. DialysisFluidFlow: dialysis_fluid_flow,
  3933. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3934. PrescriptionWater: prescription_water,
  3935. DialysisStrainer: dialysis_strainer,
  3936. Chaptalization: chaptalization,
  3937. WashingTime: washing_time,
  3938. WarshCount: warsh_count,
  3939. BloodAccessPartId: blood_access_part_id,
  3940. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3941. Dialyzate: dialyzate,
  3942. DialysisDialyszersId: dialysis_dialyszers_id,
  3943. DialysisIrrigationId: dialysis_irrigation_id,
  3944. DialysisStrainerId: dialysis_strainer_id,
  3945. FirstSuper: fisrt_sup,
  3946. IsSequential: is_sequen,
  3947. Conduct: conduct,
  3948. }
  3949. if adminUserInfo.Org.Id == 10721 {
  3950. if prescription.ModeId == 2 {
  3951. if prescription.ReplacementTotal == 0 {
  3952. prescription.ReplacementTotal = 15
  3953. }
  3954. }
  3955. }
  3956. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3957. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3958. //
  3959. if appRole.UserType == 2 || appRole.UserType == 1 {
  3960. prescription_doctor = adminUserInfo.AdminUser.Id
  3961. prescription.PrescriptionDoctor = prescription_doctor
  3962. }
  3963. if dialysisPrescription.ID == 0 { //新增
  3964. prescription.Creater = adminUserInfo.AdminUser.Id
  3965. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3966. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3967. }
  3968. } else { //修改
  3969. if dialysisPrescription.Creater == 0 {
  3970. prescription.Creater = adminUserInfo.AdminUser.Id
  3971. } else {
  3972. prescription.Creater = dialysisPrescription.Creater
  3973. if adminUserInfo.Org.Id == 9882 {
  3974. if appRole.UserType == 2 || appRole.UserType == 1 {
  3975. prescription.Creater = adminUserInfo.AdminUser.Id
  3976. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3977. }
  3978. }
  3979. }
  3980. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3981. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3982. }
  3983. //if/**/
  3984. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3985. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3986. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3987. // if getPermissionErr != nil {
  3988. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3989. // return
  3990. // } else if headNursePermission == nil {
  3991. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3992. // return
  3993. // }
  3994. //}
  3995. //prescription.Creater = dialysisPrescription.Creater
  3996. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3997. prescription.Modifier = adminUserInfo.AdminUser.Id
  3998. prescription.ID = dialysisPrescription.ID
  3999. }
  4000. solution := models.DialysisSolution{
  4001. RegistrarsId: adminUserInfo.AdminUser.Id,
  4002. UserOrgId: adminUserInfo.Org.Id,
  4003. Doctor: prescription_doctor,
  4004. PatientId: id,
  4005. ModeId: mode_id,
  4006. DialysisDuration: dialysis_duration,
  4007. PerfusionApparatus: perfusion_apparatus,
  4008. BloodFlowVolume: blood_flow_volume,
  4009. Dewater: dewater_amount,
  4010. DisplaceLiqui: displace_liqui,
  4011. ReplacementWay: replacement_way,
  4012. Anticoagulant: anticoagulant,
  4013. AnticoagulantShouji: anticoagulant_shouji,
  4014. AnticoagulantWeichi: anticoagulant_weichi,
  4015. AnticoagulantZongliang: anticoagulant_zongliang,
  4016. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4017. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4018. Kalium: kalium,
  4019. Sodium: sodium,
  4020. Calcium: calcium,
  4021. Bicarbonate: bicarbonate,
  4022. Glucose: glucose,
  4023. // DryWeight: dry_weight,
  4024. DialysateFlow: dialysate_flow,
  4025. DialysateTemperature: dialysate_temperature,
  4026. Conductivity: conductivity,
  4027. Remark: remark,
  4028. Status: 1,
  4029. CreatedTime: time.Now().Unix(),
  4030. UpdatedTime: time.Now().Unix(),
  4031. DialysisDurationMinute: dialysisDurationMinute,
  4032. DialysisDurationHour: dialysisDurationHour,
  4033. TargetUltrafiltration: targetUltrafiltration,
  4034. DialysateFormulation: dialysateFormulation,
  4035. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4036. BodyFluid: body_fluid,
  4037. SpecialMedicine: special_medicine,
  4038. SpecialMedicineOther: special_medicine_other,
  4039. DisplaceLiquiPart: displace_liqui_part,
  4040. DisplaceLiquiValue: displace_liqui_value,
  4041. BloodAccess: blood_access,
  4042. Ultrafiltration: ultrafiltration,
  4043. BodyFluidOther: body_fluid_other,
  4044. ReplacementTotal: replacement_total,
  4045. TargetKtv: target_ktv,
  4046. DialysisDialyszers: dialysis_dialyszers,
  4047. DialysisIrrigation: dialysis_irrigation,
  4048. HemodialysisPipelines: hemodialysis_pipelines,
  4049. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4050. PunctureNeedle: puncture_needle,
  4051. PunctureNeedleCount: puncture_needle_count,
  4052. Epo: epo,
  4053. EpoCount: epo_count,
  4054. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4055. PreImpulse: impulse,
  4056. SolutionStatus: 1,
  4057. DialysisRemark: dialysis_remark,
  4058. PrescribingNumber: prescribing_number,
  4059. PrescriptionSodium: prescription_sodium,
  4060. StartSodium: start_sodium,
  4061. SodiumCurve: sodium_curve,
  4062. TreatmentRemark: treatment_remark,
  4063. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4064. DialysisFluidFlow: dialysis_fluid_flow,
  4065. PrescriptionWater: prescription_water,
  4066. DialysisStrainer: dialysis_strainer,
  4067. Chaptalization: chaptalization,
  4068. WashingTime: washing_time,
  4069. WarshCount: warsh_count,
  4070. BloodAccessPartId: blood_access_part_id,
  4071. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4072. Dialyzate: dialyzate,
  4073. DialysisDialyszersId: dialysis_dialyszers_id,
  4074. DialysisIrrigationId: dialysis_irrigation_id,
  4075. DialysisStrainerId: dialysis_strainer_id,
  4076. FirstSuper: fisrt_sup,
  4077. IsSequential: is_sequen,
  4078. Conduct: conduct,
  4079. }
  4080. //针对河间咸的
  4081. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4082. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4083. solution.DisplaceLiquiPart = 0
  4084. solution.DisplaceLiquiValue = 0
  4085. }
  4086. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4087. prescription.DisplaceLiquiPart = 0
  4088. prescription.DisplaceLiquiValue = 0
  4089. }
  4090. }
  4091. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4092. if solution.PrescribingNumber == 0 {
  4093. solution.PrescribingNumber = 1
  4094. }
  4095. if prescription.PrescribingNumber == 0 {
  4096. prescription.PrescribingNumber = 1
  4097. }
  4098. if solution.PrescribingNumber == 0 && id == 14682 {
  4099. solution.PrescribingNumber = 2
  4100. }
  4101. if solution.PrescribingNumber == 0 && id == 18560 {
  4102. solution.PrescribingNumber = 2
  4103. }
  4104. if prescription.PrescribingNumber == 0 && id == 14682 {
  4105. prescription.PrescribingNumber = 2
  4106. }
  4107. if prescription.PrescribingNumber == 0 && id == 18560 {
  4108. prescription.PrescribingNumber = 2
  4109. }
  4110. }
  4111. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4112. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  4113. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4114. if len(monitorList) > 0 {
  4115. var ultrafiltration_rate float64
  4116. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4117. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4118. var replacement_rate float64
  4119. //乘10 除10是为了保留一位小数
  4120. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4121. var firstOpeateTime = monitorList[0].OperateTime
  4122. for _, item := range monitorList {
  4123. //超滤率
  4124. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4125. //置换率
  4126. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4127. //超滤量
  4128. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4129. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4130. //置换量
  4131. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4132. fmt.Println("displacement_quantity----------------------", displacement_quantity)
  4133. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4134. }
  4135. }
  4136. }
  4137. //记录日志
  4138. byterequest, _ := json.Marshal(prescription)
  4139. prescriptionLog := models.XtDialysisPrescriptionLog{
  4140. UserOrgId: prescription.UserOrgId,
  4141. Ctime: time.Now().Unix(),
  4142. Mtime: 0,
  4143. ErrLog: string(byterequest),
  4144. AdminUserId: adminUserInfo.AdminUser.Id,
  4145. RecordDate: prescription.RecordDate,
  4146. PatientId: prescription.PatientId,
  4147. Source: "手机端新增长期处方",
  4148. Status: 1,
  4149. }
  4150. service.CreatePrescriptionLog(prescriptionLog)
  4151. finish := models.XtDialysisFinish{
  4152. IsFinish: 1,
  4153. UserOrgId: adminUserInfo.Org.Id,
  4154. Status: 1,
  4155. Ctime: time.Now().Unix(),
  4156. Mtime: 0,
  4157. Module: 1,
  4158. RecordDate: recordDate.Unix(),
  4159. Sourse: 1,
  4160. PatientId: id,
  4161. }
  4162. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4163. if dialysisFinish.ID == 0 {
  4164. service.CreateDialysisFinish(finish)
  4165. }
  4166. //获取最新1条
  4167. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4168. //更新状态
  4169. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4170. //长沙南雅医院,自动生成抗凝剂的临时处方
  4171. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4172. if prescribing_number == 0 {
  4173. prescribing_number = 1
  4174. }
  4175. advice := models.DoctorAdvice{
  4176. UserOrgId: adminUserInfo.Org.Id,
  4177. PatientId: id,
  4178. GroupNo: 0,
  4179. AdviceType: 2,
  4180. RecordDate: recordDate.Unix(),
  4181. AdviceDate: recordDate.Unix(),
  4182. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4183. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4184. AdviceDesc: "",
  4185. ReminderDate: 0,
  4186. SingleDose: prescription.AnticoagulantZongliang,
  4187. SingleDoseUnit: "iu",
  4188. DrugSpec: 0,
  4189. DrugSpecUnit: "",
  4190. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4191. PrescribingNumberUnit: "支",
  4192. DeliveryWay: "静脉注射",
  4193. ExecutionFrequency: "上机前",
  4194. AdviceDoctor: 0,
  4195. Status: 1,
  4196. CreatedTime: time.Now().Unix(),
  4197. UpdatedTime: time.Now().Unix(),
  4198. IsPrescription: 1,
  4199. ExecutionState: 2,
  4200. StopState: 2,
  4201. IsSettle: 2,
  4202. }
  4203. // 查询排班信息
  4204. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4205. if schedulePatient.ID > 0 {
  4206. if schedulePatient.ScheduleType == 1 {
  4207. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4208. }
  4209. if schedulePatient.ScheduleType == 2 {
  4210. advice.StartTime = recordDate.Unix() + 9*60*60
  4211. }
  4212. }
  4213. // 抗凝剂名称
  4214. switch anticoagulant {
  4215. case 1:
  4216. advice.AdviceName = "无肝素"
  4217. break
  4218. case 2:
  4219. advice.AdviceName = "普通肝素"
  4220. break
  4221. case 3:
  4222. advice.AdviceName = "低分子肝素"
  4223. break
  4224. case 4:
  4225. advice.AdviceName = "阿加曲班"
  4226. break
  4227. case 5:
  4228. advice.AdviceName = "枸橼酸钠"
  4229. break
  4230. case 6:
  4231. advice.AdviceName = "低分子肝素钙"
  4232. break
  4233. case 7:
  4234. advice.AdviceName = "低分子肝素钠"
  4235. break
  4236. case 8:
  4237. advice.AdviceName = "依诺肝素"
  4238. break
  4239. case 9:
  4240. advice.AdviceName = "达肝素"
  4241. break
  4242. case 10:
  4243. advice.AdviceName = "体外抗凝"
  4244. break
  4245. case 11:
  4246. advice.AdviceName = "那曲肝素"
  4247. break
  4248. case 12:
  4249. advice.AdviceName = "无抗凝剂"
  4250. break
  4251. }
  4252. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4253. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4254. advice.AdviceDoctor = appRole.AdminUserId
  4255. }
  4256. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4257. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4258. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4259. advice.AdviceName = "低分子肝素钠注射液"
  4260. // 修改患者临时医嘱里的抗凝剂医嘱
  4261. advice.ID = advicePrescription.ID
  4262. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4263. } else {
  4264. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4265. advice.AdviceName = "低分子肝素钠注射液"
  4266. service.CreateDoctorAdvice(&advice)
  4267. }
  4268. }
  4269. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4270. redis := service.RedisClient()
  4271. defer redis.Close()
  4272. //清空key 值
  4273. redis.Set(key, "", time.Second)
  4274. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4275. redis.Set(keyOne, "", time.Second)
  4276. }
  4277. //获取key,清空redis
  4278. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4279. redis := service.RedisClient()
  4280. defer redis.Close()
  4281. //清空key 值
  4282. redis.Set(key, "", time.Second)
  4283. //清空长期医嘱的key
  4284. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4285. redis.Set(soulution_key, "", time.Second)
  4286. //查询最近透析准备表里是否存在 透析器 灌流器
  4287. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4288. redis.Set(keyOne, "", time.Second)
  4289. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4290. redis.Set(keyTwo, "", time.Second)
  4291. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4292. redis.Set(keyThree, "", time.Second)
  4293. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4294. redis.Set(keyFour, "", time.Second)
  4295. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4296. //
  4297. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4298. //
  4299. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4300. //if len(mation)>0{
  4301. // for _, item := range splitStr {
  4302. // for _,it := range mation{
  4303. // if(item == it.SpecificationName){
  4304. //
  4305. // //查询最近一次的透析器
  4306. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4307. //
  4308. // if errcode == gorm.ErrRecordNotFound{
  4309. // //插入数据
  4310. // prepare := models.DialysisBeforePrepare{
  4311. // UserOrgId: adminUserInfo.Org.Id,
  4312. // PatientId: id,
  4313. // RecordDate: recordDate.Unix(),
  4314. // GoodTypeId: it.GoodTypeId,
  4315. // GoodId: it.ID,
  4316. // Count: 1,
  4317. // Ctime: time.Now().Unix(),
  4318. // Creater: adminUserInfo.AdminUser.Id,
  4319. // Status:1,
  4320. //
  4321. // }
  4322. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4323. // fmt.Println("",errcode)
  4324. // }
  4325. // }
  4326. // }
  4327. //
  4328. // }
  4329. //
  4330. // for _, item := range splitIrrigation {
  4331. // for _,it := range mation{
  4332. // if(item == it.SpecificationName){
  4333. // //查询最近一次的透析器
  4334. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4335. // if errcode == gorm.ErrRecordNotFound{
  4336. // //插入数据
  4337. // prepare := models.DialysisBeforePrepare{
  4338. // UserOrgId: adminUserInfo.Org.Id,
  4339. // PatientId: id,
  4340. // RecordDate: recordDate.Unix(),
  4341. // GoodTypeId: it.GoodTypeId,
  4342. // GoodId: it.ID,
  4343. // Count: 1,
  4344. // Ctime: time.Now().Unix(),
  4345. // Creater: adminUserInfo.AdminUser.Id,
  4346. // Status:1,
  4347. //
  4348. // }
  4349. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4350. // fmt.Println(errcode)
  4351. // }
  4352. // }
  4353. // }
  4354. // }
  4355. //}
  4356. c.ServeSuccessJSON(map[string]interface{}{
  4357. "solution": &solution,
  4358. "prescription": &prescription,
  4359. })
  4360. }
  4361. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4362. patient, _ := c.GetInt64("patient", 0)
  4363. adminUserInfo := c.GetMobileAdminUserInfo()
  4364. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4365. c.ServeSuccessJSON(map[string]interface{}{
  4366. "receiveTreatmentAsses": receiveTreatmentAsses,
  4367. })
  4368. }
  4369. func (this *DialysisAPIController) PostSignInfo() {
  4370. patientID, _ := this.GetInt64("patient_id")
  4371. recordDateStr := this.GetString("date")
  4372. if patientID <= 0 {
  4373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4374. return
  4375. }
  4376. if len(recordDateStr) == 0 {
  4377. recordDateStr = time.Now().Format("2006-01-02")
  4378. }
  4379. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4380. if parseDateErr != nil {
  4381. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4382. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4383. return
  4384. }
  4385. adminInfo := this.GetMobileAdminUserInfo()
  4386. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4387. if err != nil {
  4388. this.ErrorLog("签名失败:%v", err)
  4389. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4390. return
  4391. }
  4392. this.ServeSuccessJSON(map[string]interface{}{
  4393. "doctor_id": adminInfo.AdminUser.Id,
  4394. })
  4395. }
  4396. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4397. patientID, _ := this.GetInt64("patient_id")
  4398. adminInfo := this.GetMobileAdminUserInfo()
  4399. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4400. this.ServeSuccessJSON(map[string]interface{}{
  4401. "monitor": record,
  4402. })
  4403. }
  4404. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4405. thisTime := time.Now()
  4406. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4407. timeLayout := "2006-01-02 15:04:05"
  4408. loc, _ := time.LoadLocation("Local")
  4409. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4410. theAssessmentDateTime := theStartTime.Unix()
  4411. patientID, _ := this.GetInt64("patient_id")
  4412. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4413. adminInfo := this.GetMobileAdminUserInfo()
  4414. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4415. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4416. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4417. var ultrafiltration_rate float64
  4418. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4419. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4420. fmt.Println(evaluation)
  4421. fmt.Println("prescription.ID", prescription.ID)
  4422. if prescription.ID > 0 {
  4423. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4424. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4425. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4426. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4427. record.UltrafiltrationRate = ultrafiltration_rate
  4428. }
  4429. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4430. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4431. record.UltrafiltrationRate = ultrafiltration_rate
  4432. }
  4433. if adminInfo.Org.Id == 10510 {
  4434. record.UltrafiltrationRate = 0
  4435. }
  4436. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4437. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4438. record.UltrafiltrationRate = ultrafiltration_rate
  4439. }
  4440. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4441. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4442. record.UltrafiltrationRate = ultrafiltration_rate
  4443. }
  4444. // 只针对方济医院
  4445. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4446. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4447. ultrafiltration_rate = value
  4448. record.UltrafiltrationRate = ultrafiltration_rate
  4449. }
  4450. if template.TemplateId == 41 || template.TemplateId == 47 {
  4451. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4452. record.UltrafiltrationRate = ultrafiltration_rate
  4453. }
  4454. if template.TemplateId == 43 {
  4455. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4456. record.UltrafiltrationRate = ultrafiltration_rate
  4457. }
  4458. if template.TemplateId == 46 || template.TemplateId == 54 {
  4459. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4460. record.UltrafiltrationRate = ultrafiltration_rate
  4461. }
  4462. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 {
  4463. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4464. record.UltrafiltrationRate = ultrafiltration_rate
  4465. }
  4466. if adminInfo.Org.Id == 10469 {
  4467. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4468. record.UltrafiltrationRate = ultrafiltration_rate
  4469. }
  4470. if adminInfo.Org.Id == 10667 {
  4471. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4472. record.UltrafiltrationRate = ultrafiltration_rate
  4473. }
  4474. if adminInfo.Org.Id == 10471 {
  4475. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4476. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4477. }
  4478. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4479. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4480. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4481. }
  4482. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4483. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4484. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4485. }
  4486. if adminInfo.Org.Id == 10721 {
  4487. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4488. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4489. }
  4490. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4491. record.UltrafiltrationRate = 0
  4492. }
  4493. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4494. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4495. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4496. }
  4497. if adminInfo.Org.Id == 10206 {
  4498. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4499. fmt.Println("ultrafiltration_rate------------------", ultrafiltration_rate)
  4500. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4501. }
  4502. //if template.TemplateId == 47 {
  4503. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4504. // record.UltrafiltrationRate = ultrafiltration_rate
  4505. //}
  4506. }
  4507. }
  4508. // record.UltrafiltrationRate = ultrafiltration_rate
  4509. record.UltrafiltrationVolume = 0
  4510. 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
  4511. if ultrafiltration_rate > 0 {
  4512. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4513. record.UltrafiltrationVolume = value
  4514. }
  4515. }
  4516. if template.TemplateId == 6 || template.TemplateId == 65 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 || adminInfo.Org.Id == 10599 { //adminInfo.Org.Id == 9538
  4517. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4518. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4519. record.UltrafiltrationVolume = ultrafiltration_volume
  4520. }
  4521. }
  4522. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4523. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4524. record.UltrafiltrationVolume = ultrafiltration_volume
  4525. }
  4526. //长沙南雅
  4527. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 || adminInfo.Org.Id == 10667 {
  4528. if ultrafiltration_rate > 0 {
  4529. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4530. record.UltrafiltrationVolume = ultrafiltration_volume
  4531. }
  4532. }
  4533. if adminInfo.Org.Id == 10471 {
  4534. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4535. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4536. }
  4537. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4538. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4539. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4540. }
  4541. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4542. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4543. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4544. }
  4545. //长沙南雅累计血容量自动计算
  4546. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4547. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4548. //}
  4549. if template.TemplateId == 47 || template.TemplateId == 54 {
  4550. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4551. }
  4552. if adminInfo.Org.Id == 10510 {
  4553. record.UltrafiltrationVolume = 0
  4554. }
  4555. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 {
  4556. if ultrafiltration_rate > 0 {
  4557. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4558. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4559. }
  4560. }
  4561. //古镇乐生
  4562. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4563. if ultrafiltration_rate > 0 {
  4564. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4565. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4566. }
  4567. }
  4568. if adminInfo.Org.Id == 10206 {
  4569. if ultrafiltration_rate > 0 {
  4570. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4571. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4572. }
  4573. }
  4574. if adminInfo.Org.Id == 10721 {
  4575. var replacement_rate float64
  4576. var displacement_quantity float64
  4577. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4578. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4579. record.ReplacementRate = replacement_rate
  4580. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4581. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4582. record.DisplacementQuantity = displacement_quantity
  4583. }
  4584. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4585. var replacement_rate float64
  4586. var displacement_quantity float64
  4587. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4588. if totalMin == 0 {
  4589. totalMin = 240
  4590. }
  4591. if prescription.DisplaceLiquiValue == 0 {
  4592. prescription.ReplacementTotal = 32
  4593. }
  4594. //乘10 除10是为了保留一位小数
  4595. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4596. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4597. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4598. record.DisplacementQuantity = displacement_quantity
  4599. }
  4600. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4601. this.ServeSuccessJSON(map[string]interface{}{
  4602. "monitor": record,
  4603. "lastMonitorRecordList": lastMonitorRecordList,
  4604. })
  4605. }
  4606. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4607. record_id, _ := this.GetInt64("id")
  4608. nurseID, _ := this.GetInt64("start_nurse")
  4609. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4610. bedID, _ := this.GetInt64("bed")
  4611. start_time := this.GetString("start_time")
  4612. schedual_type, _ := this.GetInt64("schedual_type")
  4613. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4614. change_nurse, _ := this.GetInt64("change_nurse")
  4615. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4616. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4617. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4618. patient_id, _ := this.GetInt64("patient_id")
  4619. record_date, _ := this.GetInt64("record_date")
  4620. puncture_needle := this.GetString("puncture_needle")
  4621. puncture_way := this.GetString("puncture_way")
  4622. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4623. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4624. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4625. nuclein_date_str := this.GetString("nuclein_date_str")
  4626. order_remark := this.GetString("order_remark")
  4627. schedule_remark := this.GetString("schedule_remark")
  4628. catheter_operation := this.GetString("catheter_operation")
  4629. blood_flow_volume := this.GetString("blood_flow_volume")
  4630. blood_drawing, _ := this.GetInt64("blood_drawing")
  4631. dialysis_strainer := this.GetString("dialysis_strainer")
  4632. if record_id == 0 {
  4633. this.ErrorLog("id:%v", record_id)
  4634. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4635. return
  4636. }
  4637. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4638. if parseStartDateErr != nil {
  4639. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4640. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4641. return
  4642. }
  4643. adminUserInfo := this.GetMobileAdminUserInfo()
  4644. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4645. if getNurseErr != nil {
  4646. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4647. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4648. return
  4649. } else if nurse == nil {
  4650. this.ErrorLog("护士不存在")
  4651. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4652. return
  4653. }
  4654. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4655. //if getNurseErr != nil {
  4656. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4657. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4658. // return
  4659. //} else if nurse == nil {
  4660. // this.ErrorLog("护士不存在")
  4661. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4662. // return
  4663. //}
  4664. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4665. if getDeviceNumberErr != nil {
  4666. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4668. return
  4669. } else if deviceNumber == nil {
  4670. this.ErrorLog("床位号不存在")
  4671. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4672. return
  4673. }
  4674. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4675. //
  4676. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4677. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4678. // if getPermissionErr != nil {
  4679. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4680. // return
  4681. // } else if headNursePermission == nil {
  4682. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4683. // return
  4684. // }
  4685. //}
  4686. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4687. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4688. timeLayout := "2006-01-02 15:04:05"
  4689. loc, _ := time.LoadLocation("Local")
  4690. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4691. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4692. schedulestartTime := theStartTime.Unix()
  4693. scheduleendTime := theEndTime.Unix()
  4694. var theNucleinDate int64
  4695. timeLayoutOne := "2006-01-02"
  4696. if len(nuclein_date_str) > 0 {
  4697. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4698. if err != nil {
  4699. utils.ErrorLog(err.Error())
  4700. }
  4701. theNucleinDate = theTime.Unix()
  4702. }
  4703. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4704. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4705. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4706. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4707. if err == gorm.ErrRecordNotFound { //空床位
  4708. // 修改了床位逻辑
  4709. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4710. if daySchedule.ID > 0 {
  4711. //daySchedule.BedId = bedID
  4712. //daySchedule.PartitionId = deviceNumber.ZoneID
  4713. //daySchedule.ScheduleType = schedual_type
  4714. //daySchedule.UpdatedTime = time.Now().Unix()
  4715. //err := service.UpdateSchedule(&daySchedule)
  4716. xtSchedule := models.Schedule{
  4717. PartitionId: deviceNumber.ZoneID,
  4718. BedId: bedID,
  4719. ScheduleType: schedual_type,
  4720. UpdatedTime: time.Now().Unix(),
  4721. }
  4722. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4723. if err != nil {
  4724. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4725. return
  4726. }
  4727. }
  4728. } else if err == nil {
  4729. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4730. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4731. if daySchedule.ID > 0 {
  4732. //daySchedule.BedId = bedID
  4733. //daySchedule.PartitionId = deviceNumber.ZoneID
  4734. //
  4735. //daySchedule.ScheduleType = schedual_type
  4736. //daySchedule.UpdatedTime = time.Now().Unix()
  4737. //err := service.UpdateSchedule(&daySchedule)
  4738. xtSchedule := models.Schedule{
  4739. PartitionId: deviceNumber.ZoneID,
  4740. BedId: bedID,
  4741. ScheduleType: schedual_type,
  4742. UpdatedTime: time.Now().Unix(),
  4743. }
  4744. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4745. if err != nil {
  4746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4747. return
  4748. }
  4749. }
  4750. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4751. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4752. return
  4753. }
  4754. } else if err != nil {
  4755. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4756. return
  4757. }
  4758. }
  4759. dialysisRecord := &models.DialysisOrder{
  4760. ID: record_id,
  4761. UserOrgId: adminUserInfo.Org.Id,
  4762. BedID: bedID,
  4763. StartNurse: nurseID,
  4764. StartTime: startDate.Unix(),
  4765. PunctureNurse: puncture_nurse,
  4766. Creator: adminUserInfo.AdminUser.Id,
  4767. Modifier: adminUserInfo.AdminUser.Id,
  4768. WashpipeNurse: washpipe_nurse,
  4769. SchedualType: schedual_type,
  4770. ChangeNurse: change_nurse,
  4771. DifficultPunctureNurse: difficult_puncture_nurse,
  4772. NewFistulaNurse: new_fistula_nurse,
  4773. QualityNurseId: quality_nurse_id,
  4774. PunctureNeedle: puncture_needle,
  4775. PunctureWay: puncture_way,
  4776. DialysisDialyszers: dialysis_dialyszers,
  4777. DialysisIrrigation: dialysis_irrigation,
  4778. BloodAccessId: blood_access_id,
  4779. NucleinDate: theNucleinDate,
  4780. OrderRemark: order_remark,
  4781. ScheduleRemark: schedule_remark,
  4782. CatheterOperation: catheter_operation,
  4783. BloodFlowVolume: blood_flow_volume,
  4784. BloodDrawing: blood_drawing,
  4785. DialysisStrainer: dialysis_strainer,
  4786. }
  4787. //修改床位号需要重新消毒
  4788. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4789. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4790. //查询第一条监测
  4791. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4792. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4793. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4794. redis := service.RedisClient()
  4795. //清空key 值
  4796. redis.Set(key, "", time.Second)
  4797. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4798. redis.Set(keyOne, "", time.Second)
  4799. defer redis.Close()
  4800. }
  4801. // 查询信息规挡的设置天数
  4802. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4803. if infor.ID > 0 && infor.WeekDay > 0 {
  4804. var cha_time int64
  4805. timeNowStr := time.Now().Format("2006-01-02")
  4806. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4807. //今日的日期减去设置的日期
  4808. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4809. if cha_time >= record_date {
  4810. //查询审核是否允许
  4811. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4812. //申请状态不允许的情况 拒绝修改
  4813. if infor.ApplicationStatus != 1 {
  4814. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4815. return
  4816. }
  4817. }
  4818. }
  4819. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4820. //修改床位后重新生成消毒计划
  4821. if adminUserInfo.Org.Id == 10340 {
  4822. //根据床位号获取设备型号
  4823. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4824. //查询使用消毒最后一条消毒记录
  4825. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4826. fmt.Println("err", err)
  4827. if err == gorm.ErrRecordNotFound {
  4828. //查找排班
  4829. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4830. //查询改设备是否有消毒计划
  4831. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4832. //根据床位号获取设备id
  4833. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4834. //查询病人信息
  4835. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4836. var con = ""
  4837. if patients.IsInfectious == 0 {
  4838. con = ""
  4839. }
  4840. if patients.IsInfectious == 1 {
  4841. con = "无"
  4842. }
  4843. if patients.IsInfectious == 2 {
  4844. con = "有"
  4845. }
  4846. if errcode == nil {
  4847. var end_time int64
  4848. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4849. //新增消毒
  4850. information := models.DeviceInformation{
  4851. Date: dialysisRecord.DialysisDate,
  4852. Zone: dialysisRecord.ZoneId,
  4853. Class: dialysisRecord.SchedualType,
  4854. BedNumber: dialysisRecord.BedID,
  4855. PatientId: dialysisRecord.PatientId,
  4856. DialysisMode: scheduleByPatient.ModeId,
  4857. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4858. Disinfection: 1,
  4859. DialysisConcentration: 1,
  4860. DisinfectionStatus: 1,
  4861. Move: 1,
  4862. UserOrgId: dialysisRecord.UserOrgId,
  4863. DisinfectType: plan.Way,
  4864. DisinfectantType: plan.MachineDisinfectant,
  4865. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4866. Disinfectant: plan.Disinfectant,
  4867. Ctime: time.Now().Unix(),
  4868. Status: 1,
  4869. SignName: nurseID,
  4870. EquimentId: addmacher.ID,
  4871. DisinfectionResidue: 2,
  4872. Bed: addmacher.BedNumber,
  4873. StartTime: dialysisRecord.StartTime,
  4874. EndTime: dialysisRecord.EndTime,
  4875. Contagion: con,
  4876. WeightLoss: 0,
  4877. Hyperfiltratio: 0,
  4878. DialysisHour: "",
  4879. MachineRun: 1,
  4880. DisinfecStartime: dialysisRecord.EndTime,
  4881. DisinfecEndtime: end_time,
  4882. }
  4883. err := service.CreateInformationTwo(&information)
  4884. fmt.Println("报错", err)
  4885. }
  4886. }
  4887. }
  4888. order, _ := service.GetLastPatientOrder(record_id)
  4889. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4890. redis := service.RedisClient()
  4891. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4892. redis.Set(key, "", time.Second)
  4893. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4894. //清空key 值
  4895. redis.Set(keyOne, "", time.Second)
  4896. scheduleDateStartOne := startDate.Format("2006-01-02")
  4897. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4898. redis.Set(keyTwo, "", time.Second)
  4899. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4900. redis.Set(keyThree, "", time.Second)
  4901. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4902. redis.Set(keyFour, "", time.Second)
  4903. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4904. redis.Set(keyFive, "", time.Second)
  4905. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4906. redis.Set(keySix, "", time.Second)
  4907. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4908. redis.Set(keySeven, "", time.Second)
  4909. if updateErr != nil {
  4910. this.ErrorLog("修改上机失败:%v", updateErr)
  4911. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4912. return
  4913. }
  4914. if updateErr == nil {
  4915. if tempDialysisRecord.Stage == 2 {
  4916. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4917. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4918. fmt.Println(value)
  4919. a, b := math.Modf(value)
  4920. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4921. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4922. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4923. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4924. redis := service.RedisClient()
  4925. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4926. redis.Set(key, "", time.Second)
  4927. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4928. redis.Set(keyOne, "", time.Second)
  4929. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4930. //清空key 值
  4931. redis.Set(keySix, "", time.Second)
  4932. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4933. redis.Set(keySeven, "", time.Second)
  4934. redis.Close()
  4935. if updateAssessmentErr != nil {
  4936. utils.ErrorLog("%v", updateAssessmentErr)
  4937. }
  4938. }
  4939. }
  4940. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4941. this.ServeSuccessJSON(map[string]interface{}{
  4942. "dialysis_order": dialysisRecords,
  4943. })
  4944. }
  4945. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4946. record_id, _ := c.GetInt64("id")
  4947. nurseID, _ := c.GetInt64("nurse")
  4948. end_time := c.GetString("end_time")
  4949. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4950. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4951. catheter := c.GetString("catheter")
  4952. cruor := c.GetString("cruor")
  4953. mission := c.GetString("mission")
  4954. condenser := c.GetString("condenser")
  4955. if record_id <= 0 || nurseID <= 0 {
  4956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4957. return
  4958. }
  4959. adminUserInfo := c.GetMobileAdminUserInfo()
  4960. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4961. if getNurseErr != nil {
  4962. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4964. return
  4965. } else if nurse == nil {
  4966. c.ErrorLog("护士不存在")
  4967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4968. return
  4969. }
  4970. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4971. if parseEndDateErr != nil {
  4972. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4974. return
  4975. }
  4976. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4977. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4978. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4979. // if getPermissionErr != nil {
  4980. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4981. // return
  4982. // } else if headNursePermission == nil {
  4983. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4984. // return
  4985. // }
  4986. //}
  4987. // 查询信息规挡的设置天数
  4988. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4989. if infor.ID > 0 {
  4990. var cha_time int64
  4991. timeNowStr := time.Now().Format("2006-01-02")
  4992. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4993. //今日的日期减去设置的日期
  4994. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4995. if cha_time >= tempDialysisRecords.DialysisDate {
  4996. //查询审核是否允许
  4997. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4998. //申请状态不允许的情况 拒绝修改
  4999. if infor.ApplicationStatus != 1 {
  5000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5001. return
  5002. }
  5003. }
  5004. }
  5005. dialysisRecord := &models.DialysisOrder{
  5006. ID: record_id,
  5007. UserOrgId: adminUserInfo.Org.Id,
  5008. EndTime: endDate.Unix(),
  5009. FinishNurse: nurseID,
  5010. FinishModifier: adminUserInfo.AdminUser.Id,
  5011. PuncturePointHaematoma: puncture_point_haematoma,
  5012. BloodAccessInternalFistula: blood_access_internal_fistula,
  5013. Catheter: catheter,
  5014. Cruor: cruor,
  5015. Mission: mission,
  5016. Condenser: condenser,
  5017. }
  5018. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5019. redis := service.RedisClient()
  5020. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5021. //清空key 值
  5022. redis.Set(key, "", time.Second)
  5023. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5024. //清空key 值
  5025. redis.Set(keyOne, "", time.Second)
  5026. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5027. redis.Set(keySeven, "", time.Second)
  5028. redis.Close()
  5029. if updateErr != nil {
  5030. c.ErrorLog("修改下机失败:%v", updateErr)
  5031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5032. return
  5033. }
  5034. if updateErr == nil {
  5035. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5036. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5037. a, b := math.Modf(value)
  5038. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5039. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5040. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5041. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5042. redis := service.RedisClient()
  5043. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5044. redis.Set(keyTen, "", time.Second)
  5045. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5046. redis.Set(keyTwo, "", time.Second)
  5047. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5048. redis.Set(key, "", time.Second)
  5049. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5050. redis.Set(keyThree, "", time.Second)
  5051. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5052. redis.Set(keySeven, "", time.Second)
  5053. defer redis.Close()
  5054. if updateAssessmentErr != nil {
  5055. utils.ErrorLog("%v", updateAssessmentErr)
  5056. }
  5057. }
  5058. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5059. c.ServeSuccessJSON(map[string]interface{}{
  5060. "dialysis_order": dialysisRecords,
  5061. })
  5062. }
  5063. func (c *DialysisAPIController) GetLongAdvice() {
  5064. patient_id, _ := c.GetInt64("id")
  5065. adminUserInfo := c.GetMobileAdminUserInfo()
  5066. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5067. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5068. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5069. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5070. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5071. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5072. c.ServeSuccessJSON(map[string]interface{}{
  5073. "status": "1",
  5074. })
  5075. return
  5076. } else { //开启推送提醒
  5077. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5078. var advice_three []*models.DoctorAdvice
  5079. recordDateStr := time.Now().Format("2006-01-02")
  5080. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5081. nowtime := recordDate.Unix()
  5082. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5083. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5084. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5085. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5086. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5087. for _, advice := range advices {
  5088. if advice.FrequencyType == 3 {
  5089. t := time.Now()
  5090. week := int(t.Weekday())
  5091. fmt.Println(t.Weekday())
  5092. fmt.Println(week)
  5093. switch week {
  5094. case 1:
  5095. if strings.Index(advice.WeekDay, "周一") == -1 {
  5096. advice_three = append(advice_three, advice)
  5097. }
  5098. break
  5099. case 2:
  5100. if strings.Index(advice.WeekDay, "周二") == -1 {
  5101. advice_three = append(advice_three, advice)
  5102. }
  5103. break
  5104. case 3:
  5105. if strings.Index(advice.WeekDay, "周三") == -1 {
  5106. advice_three = append(advice_three, advice)
  5107. }
  5108. break
  5109. case 4:
  5110. if strings.Index(advice.WeekDay, "周四") == -1 {
  5111. advice_three = append(advice_three, advice)
  5112. }
  5113. break
  5114. case 5:
  5115. if strings.Index(advice.WeekDay, "周五") == -1 {
  5116. advice_three = append(advice_three, advice)
  5117. }
  5118. break
  5119. case 6:
  5120. if strings.Index(advice.WeekDay, "周六") == -1 {
  5121. advice_three = append(advice_three, advice)
  5122. }
  5123. break
  5124. case 0:
  5125. if strings.Index(advice.WeekDay, "周日") == -1 {
  5126. advice_three = append(advice_three, advice)
  5127. }
  5128. break
  5129. }
  5130. }
  5131. }
  5132. for _, advice := range advices_two {
  5133. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5134. now := p.Unix()
  5135. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5136. dayStr2 := "-" + dayStr
  5137. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5138. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5139. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5140. for _, ad := range advices {
  5141. advice_three = append(advice_three, ad)
  5142. }
  5143. }
  5144. if err == nil {
  5145. c.ServeSuccessJSON(map[string]interface{}{
  5146. "status": "2",
  5147. "advices": advices,
  5148. "advices_two": RemoveRepeatedElement(advice_three),
  5149. "is_open_remind": config.IsOpenRemind,
  5150. "his_config_open": hisConfig.IsOpen,
  5151. "is_advice_open": is_advice_open.IsAdviceOpen,
  5152. "prescription_open": prescription_open.IsOpen,
  5153. })
  5154. }
  5155. }
  5156. }
  5157. func (c *DialysisAPIController) GetLongAdviceOne() {
  5158. patient_id, _ := c.GetInt64("id")
  5159. startTime := c.GetString("schedule_date")
  5160. timeLayout := "2006-01-02"
  5161. loc, _ := time.LoadLocation("Local")
  5162. var theStartTime int64
  5163. if len(startTime) > 0 {
  5164. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5165. if err != nil {
  5166. utils.ErrorLog(err.Error())
  5167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5168. return
  5169. }
  5170. theStartTime = theTime.Unix()
  5171. }
  5172. adminUserInfo := c.GetMobileAdminUserInfo()
  5173. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5174. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5175. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5176. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5177. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5178. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5179. c.ServeSuccessJSON(map[string]interface{}{
  5180. "status": "1",
  5181. })
  5182. return
  5183. } else { //开启推送提醒
  5184. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5185. var advice_three []*models.DoctorAdvice
  5186. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5187. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5188. for _, advice := range advices {
  5189. if advice.FrequencyType == 3 {
  5190. t := time.Now()
  5191. week := int(t.Weekday())
  5192. fmt.Println(t.Weekday())
  5193. fmt.Println(week)
  5194. switch week {
  5195. case 1:
  5196. if strings.Index(advice.WeekDay, "周一") == -1 {
  5197. advice_three = append(advice_three, advice)
  5198. }
  5199. break
  5200. case 2:
  5201. if strings.Index(advice.WeekDay, "周二") == -1 {
  5202. advice_three = append(advice_three, advice)
  5203. }
  5204. break
  5205. case 3:
  5206. if strings.Index(advice.WeekDay, "周三") == -1 {
  5207. advice_three = append(advice_three, advice)
  5208. }
  5209. break
  5210. case 4:
  5211. if strings.Index(advice.WeekDay, "周四") == -1 {
  5212. advice_three = append(advice_three, advice)
  5213. }
  5214. break
  5215. case 5:
  5216. if strings.Index(advice.WeekDay, "周五") == -1 {
  5217. advice_three = append(advice_three, advice)
  5218. }
  5219. break
  5220. case 6:
  5221. if strings.Index(advice.WeekDay, "周六") == -1 {
  5222. advice_three = append(advice_three, advice)
  5223. }
  5224. break
  5225. case 0:
  5226. if strings.Index(advice.WeekDay, "周日") == -1 {
  5227. advice_three = append(advice_three, advice)
  5228. }
  5229. break
  5230. }
  5231. }
  5232. }
  5233. for _, advice := range advices_two {
  5234. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5235. now := p.Unix()
  5236. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5237. dayStr2 := "-" + dayStr
  5238. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5239. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5240. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5241. for _, ad := range advices {
  5242. advice_three = append(advice_three, ad)
  5243. }
  5244. }
  5245. if err == nil {
  5246. c.ServeSuccessJSON(map[string]interface{}{
  5247. "status": "2",
  5248. "advices": advices,
  5249. "advices_two": RemoveRepeatedElement(advice_three),
  5250. "is_open_remind": config.IsOpenRemind,
  5251. "his_config_open": hisConfig.IsOpen,
  5252. "is_advice_open": is_advice_open.IsAdviceOpen,
  5253. "prescription_open": prescription_open.IsOpen,
  5254. })
  5255. }
  5256. }
  5257. }
  5258. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5259. newArr = make([]*models.DoctorAdvice, 0)
  5260. for i := 0; i < len(arr); i++ {
  5261. repeat := false
  5262. for j := i + 1; j < len(arr); j++ {
  5263. if arr[i].ID == arr[j].ID {
  5264. repeat = true
  5265. break
  5266. }
  5267. }
  5268. if !repeat {
  5269. newArr = append(newArr, arr[i])
  5270. }
  5271. }
  5272. return
  5273. }
  5274. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5275. patient, _ := c.GetInt64("id", 0)
  5276. groupNo, _ := c.GetInt64("groupno", 0)
  5277. if patient <= 0 {
  5278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5279. return
  5280. }
  5281. adminUserInfo := c.GetMobileAdminUserInfo()
  5282. dataBody := make(map[string]interface{}, 0)
  5283. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5284. if err != nil {
  5285. utils.ErrorLog(err.Error())
  5286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5287. return
  5288. }
  5289. utils.ErrorLog("%v", dataBody)
  5290. timeLayout := "2006-01-02 15:04"
  5291. loc, _ := time.LoadLocation("Local")
  5292. timeLayout2 := "2006-01-02"
  5293. loc2, _ := time.LoadLocation("Local")
  5294. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5295. utils.ErrorLog("advice_type")
  5296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5297. return
  5298. }
  5299. adviceType := int64(2)
  5300. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5301. utils.ErrorLog("advice_date")
  5302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5303. return
  5304. }
  5305. adviceDate, _ := dataBody["advice_date"].(string)
  5306. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5307. AdviceDate := theTime.Unix()
  5308. RecordDate := theTime.Unix()
  5309. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5310. utils.ErrorLog("start_time")
  5311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5312. return
  5313. }
  5314. startTime, _ := dataBody["start_time"].(string)
  5315. if len(startTime) == 0 {
  5316. utils.ErrorLog("len(start_time) == 0")
  5317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5318. return
  5319. }
  5320. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5321. if err != nil {
  5322. utils.ErrorLog(err.Error())
  5323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5324. return
  5325. }
  5326. StartTime := theTime.Unix()
  5327. Remark := ""
  5328. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5329. remark, _ := dataBody["remark"].(string)
  5330. Remark = remark
  5331. }
  5332. var advices []*models.GroupAdvice
  5333. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5334. utils.ErrorLog("advices")
  5335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5336. return
  5337. }
  5338. adviceNames := dataBody["advices"].([]interface{})
  5339. for _, adviceNameMap := range adviceNames {
  5340. adviceNameM := adviceNameMap.(map[string]interface{})
  5341. var advice models.GroupAdvice
  5342. advice.Remark = Remark
  5343. advice.AdviceType = adviceType
  5344. advice.StartTime = StartTime
  5345. advice.AdviceDate = AdviceDate
  5346. advice.RecordDate = RecordDate
  5347. advice.Status = 1
  5348. advice.CreatedTime = time.Now().Unix()
  5349. advice.UpdatedTime = time.Now().Unix()
  5350. advice.StopState = 2
  5351. advice.ExecutionState = 2
  5352. advice.UserOrgId = adminUserInfo.Org.Id
  5353. advice.PatientId = patient
  5354. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5355. advice.IsSettle = 2
  5356. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5357. utils.ErrorLog("advice_name")
  5358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5359. return
  5360. }
  5361. adviceName, _ := adviceNameM["advice_name"].(string)
  5362. if len(adviceName) == 0 {
  5363. utils.ErrorLog("len(advice_name) == 0")
  5364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5365. return
  5366. }
  5367. advice.AdviceName = adviceName
  5368. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5369. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5370. advice.DrugSpec = drugSpec
  5371. }
  5372. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5373. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5374. advice.AdviceDesc = adviceDesc
  5375. }
  5376. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5377. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5378. advice.DrugSpecUnit = drugSpecUnit
  5379. }
  5380. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5381. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5382. // advice.SingleDose = singleDose
  5383. //}
  5384. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5385. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5386. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5387. }
  5388. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5389. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5390. advice.SingleDoseUnit = singleDoseUnit
  5391. }
  5392. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5393. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5394. // advice.PrescribingNumber = prescribingNumber
  5395. //}
  5396. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5397. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5398. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5399. }
  5400. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5401. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5402. advice.PrescribingNumberUnit = prescribingNumberUnit
  5403. }
  5404. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5405. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5406. advice.DeliveryWay = deliveryWay
  5407. }
  5408. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5409. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5410. advice.ExecutionFrequency = executionFrequency
  5411. }
  5412. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5413. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5414. advice.FrequencyType = frequency_type
  5415. }
  5416. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5417. day_count := int64(adviceNameM["day_count"].(float64))
  5418. advice.DayCount = day_count
  5419. }
  5420. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5421. week_day, _ := adviceNameM["week_day"].(string)
  5422. advice.WeekDay = week_day
  5423. }
  5424. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5425. way := int64(adviceNameM["way"].(float64))
  5426. advice.Way = way
  5427. }
  5428. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5429. drug_id := int64(adviceNameM["drug_id"].(float64))
  5430. advice.DrugId = drug_id
  5431. }
  5432. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5433. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5434. advice.DrugNameId = drug_name_id
  5435. }
  5436. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5437. remark, _ := adviceNameM["remark"].(string)
  5438. advice.Remark = remark
  5439. }
  5440. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5441. groupno := int64(adviceNameM["groupno"].(float64))
  5442. advice.GroupNo = groupno
  5443. }
  5444. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5445. template_id, _ := adviceNameM["template_id"].(string)
  5446. advice.TemplateId = template_id
  5447. }
  5448. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5449. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5450. advice.ExecutionFrequency = executionFrequency
  5451. }
  5452. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5453. children := adviceNameM["child"].([]interface{})
  5454. if len(children) > 0 {
  5455. for _, childrenMap := range children {
  5456. childMap := childrenMap.(map[string]interface{})
  5457. var child models.GroupAdvice
  5458. child.Remark = Remark
  5459. child.AdviceType = adviceType
  5460. child.StartTime = StartTime
  5461. child.AdviceDate = AdviceDate
  5462. child.RecordDate = RecordDate
  5463. child.Status = 1
  5464. child.CreatedTime = time.Now().Unix()
  5465. child.UpdatedTime = time.Now().Unix()
  5466. child.StopState = 2
  5467. child.ExecutionState = 2
  5468. child.UserOrgId = adminUserInfo.Org.Id
  5469. child.PatientId = patient
  5470. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5471. child.IsSettle = 1
  5472. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5473. utils.ErrorLog("child advice_name")
  5474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5475. return
  5476. }
  5477. childAdviceName, _ := childMap["advice_name"].(string)
  5478. if len(childAdviceName) == 0 {
  5479. utils.ErrorLog("len(child advice_name) == 0")
  5480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5481. return
  5482. }
  5483. child.AdviceName = childAdviceName
  5484. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5485. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5486. child.AdviceDesc = childAdviceDesc
  5487. }
  5488. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5489. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5490. child.DrugSpec = childDrugSpec
  5491. }
  5492. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5493. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5494. child.DrugSpecUnit = childDrugSpecUnit
  5495. }
  5496. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5497. child.SingleDose = childMap["single_dose"].(float64)
  5498. }
  5499. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5500. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5501. child.SingleDoseUnit = childSingleDoseUnit
  5502. }
  5503. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5504. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5505. }
  5506. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5507. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5508. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5509. }
  5510. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5511. groupno := int64(childMap["groupno"].(float64))
  5512. advice.GroupNo = groupno
  5513. }
  5514. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5515. remark, _ := childMap["remark"].(string)
  5516. child.Remark = remark
  5517. }
  5518. child.DeliveryWay = advice.DeliveryWay
  5519. child.ExecutionFrequency = advice.ExecutionFrequency
  5520. advice.Children = append(advice.Children, &child)
  5521. }
  5522. }
  5523. }
  5524. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5525. if temp_advice.ID == 0 {
  5526. advices = append(advices, &advice)
  5527. }
  5528. }
  5529. if len(advices) > 0 {
  5530. finish := models.XtDialysisFinish{
  5531. IsFinish: 1,
  5532. UserOrgId: adminUserInfo.Org.Id,
  5533. Status: 1,
  5534. Ctime: time.Now().Unix(),
  5535. Mtime: 0,
  5536. Module: 4,
  5537. RecordDate: AdviceDate,
  5538. Sourse: 1,
  5539. PatientId: patient,
  5540. }
  5541. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5542. if dialysisFinish.ID == 0 {
  5543. service.CreateDialysisFinish(finish)
  5544. }
  5545. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5546. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5547. for _, item := range advices {
  5548. byterequest, _ := json.Marshal(item)
  5549. adviceLog := models.XtDoctorAdviceLog{
  5550. UserOrgId: adminUserInfo.Org.Id,
  5551. PatientId: patient,
  5552. AdminUserId: adminUserInfo.AdminUser.Id,
  5553. Module: 1,
  5554. ErrLog: string(byterequest),
  5555. Status: 1,
  5556. Ctime: time.Now().Unix(),
  5557. Mtime: 0,
  5558. Source: "手机端医嘱推送",
  5559. RecordDate: item.AdviceDate,
  5560. }
  5561. service.CreateDoctorAdviceLog(adviceLog)
  5562. }
  5563. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5564. redis := service.RedisClient()
  5565. //清空key 值
  5566. redis.Set(key, "", time.Second)
  5567. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5568. redis.Set(keyOne, "", time.Second)
  5569. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5570. defer redis.Close()
  5571. redis.Set(keyThree, "", time.Second)
  5572. if err != nil {
  5573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5574. return
  5575. }
  5576. c.ServeSuccessJSON(map[string]interface{}{
  5577. "msg": "ok",
  5578. "advices": list,
  5579. })
  5580. } else {
  5581. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5582. for _, item := range advices {
  5583. byterequest, _ := json.Marshal(item)
  5584. adviceLog := models.XtDoctorAdviceLog{
  5585. UserOrgId: adminUserInfo.Org.Id,
  5586. PatientId: patient,
  5587. AdminUserId: adminUserInfo.AdminUser.Id,
  5588. Module: 1,
  5589. ErrLog: string(byterequest),
  5590. Status: 1,
  5591. Ctime: time.Now().Unix(),
  5592. Mtime: 0,
  5593. Source: "手机端医嘱推送",
  5594. RecordDate: item.AdviceDate,
  5595. }
  5596. service.CreateDoctorAdviceLog(adviceLog)
  5597. }
  5598. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5599. redis := service.RedisClient()
  5600. //清空key 值
  5601. redis.Set(key, "", time.Second)
  5602. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5603. redis.Set(keyOne, "", time.Second)
  5604. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5605. defer redis.Close()
  5606. redis.Set(keyThree, "", time.Second)
  5607. if err != nil {
  5608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5609. return
  5610. }
  5611. c.ServeSuccessJSON(map[string]interface{}{
  5612. "msg": "ok",
  5613. "advices": list,
  5614. })
  5615. }
  5616. } else {
  5617. c.ServeSuccessJSON(map[string]interface{}{
  5618. "msg": "ok",
  5619. })
  5620. }
  5621. return
  5622. }
  5623. func (c *DialysisAPIController) UploadDryWeight() {
  5624. patient_id, _ := c.GetInt64("id")
  5625. dry_weight, _ := c.GetFloat("dry_weight")
  5626. doctor_id, _ := c.GetInt64("doctor_id")
  5627. remark := c.GetString("remark")
  5628. adminUserInfo := c.GetMobileAdminUserInfo()
  5629. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5630. if err == gorm.ErrRecordNotFound {
  5631. dryWeight := &models.SgjPatientDryweight{
  5632. PatientId: patient_id,
  5633. DryWeight: dry_weight,
  5634. Remakes: remark,
  5635. Ctime: time.Now().Unix(),
  5636. Mtime: time.Now().Unix(),
  5637. Creator: doctor_id,
  5638. Status: 1,
  5639. UserOrgId: adminUserInfo.Org.Id,
  5640. AdjustedValue: "/",
  5641. UserId: adminUserInfo.AdminUser.Id,
  5642. }
  5643. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5644. redis := service.RedisClient()
  5645. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5646. redis.Set(keyOne, "", time.Second)
  5647. loc, _ := time.LoadLocation("Local")
  5648. nowTime := time.Now()
  5649. nowDay := nowTime.Format("2006-01-02")
  5650. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5651. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5652. redis.Set(key, "", time.Second)
  5653. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5654. redis.Set(keyTwo, "", time.Second)
  5655. redis.Close()
  5656. if createErr == nil {
  5657. c.ServeSuccessJSON(map[string]interface{}{
  5658. "msg": "提交成功",
  5659. "weight": dryWeight,
  5660. })
  5661. }
  5662. } else {
  5663. dryWeight := &models.SgjPatientDryweight{
  5664. PatientId: patient_id,
  5665. DryWeight: dry_weight,
  5666. Remakes: remark,
  5667. Ctime: time.Now().Unix(),
  5668. Mtime: time.Now().Unix(),
  5669. Creator: doctor_id,
  5670. Status: 1,
  5671. UserOrgId: adminUserInfo.Org.Id,
  5672. AdjustedValue: "/",
  5673. UserId: adminUserInfo.AdminUser.Id,
  5674. }
  5675. var value float64
  5676. value = dry_weight - weightAdjust.DryWeight
  5677. if value < 0 {
  5678. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5679. } else if value == 0 {
  5680. dryWeight.AdjustedValue = "/"
  5681. } else if value > 0 {
  5682. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5683. }
  5684. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5685. //康桥
  5686. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5687. timeNowStr := time.Now().Format("2006-01-02")
  5688. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5689. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5690. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5691. if beforAssesment.ID > 0 {
  5692. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5693. var dewater_amount float64
  5694. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5695. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5696. //获取key,清空redis
  5697. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5698. redis := service.RedisClient()
  5699. //清空key 值
  5700. redis.Set(key, "", time.Second)
  5701. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5702. //清空key 值
  5703. redis.Set(keyOne, "", time.Second)
  5704. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5705. //清空key 值
  5706. redis.Set(keyTwo, "", time.Second)
  5707. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5708. redis.Set(keySix, "", time.Second)
  5709. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5710. redis.Set(keySeven, "", time.Second)
  5711. }
  5712. }
  5713. redis := service.RedisClient()
  5714. loc, _ := time.LoadLocation("Local")
  5715. nowTime := time.Now()
  5716. nowDay := nowTime.Format("2006-01-02")
  5717. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5718. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5719. redis.Set(keyOne, "", time.Second)
  5720. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5721. redis.Set(key, "", time.Second)
  5722. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5723. redis.Set(keyTwo, "", time.Second)
  5724. redis.Close()
  5725. if createErr == nil {
  5726. c.ServeSuccessJSON(map[string]interface{}{
  5727. "msg": "提交成功",
  5728. "weight": dryWeight,
  5729. })
  5730. }
  5731. }
  5732. }
  5733. func (c *DialysisAPIController) GetSolution() {
  5734. patient_id, _ := c.GetInt64("patient_id")
  5735. mode_id, _ := c.GetInt64("mode_id")
  5736. adminUserInfo := c.GetMobileAdminUserInfo()
  5737. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5738. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5739. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5740. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5741. if err != nil {
  5742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5743. return
  5744. }
  5745. c.ServeSuccessJSON(map[string]interface{}{
  5746. "solution": solution,
  5747. "prescription": prescription,
  5748. "system_prescription": system_prescription,
  5749. "dialysisPrescription": dialysisPrescription,
  5750. })
  5751. }
  5752. func (c *DialysisAPIController) GetSchedule() {
  5753. schedual_type, _ := c.GetInt64("schedual_type")
  5754. adminUserInfo := c.GetMobileAdminUserInfo()
  5755. scheduleTime, _ := c.GetInt64("record_date")
  5756. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5757. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5758. c.ServeSuccessJSON(map[string]interface{}{
  5759. "number": deviceNumber,
  5760. "list": list,
  5761. })
  5762. }
  5763. func (c *DialysisAPIController) GetPatientId() {
  5764. id, _ := c.GetInt64("id")
  5765. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5766. patientId, _ := service.GetPatientId(id)
  5767. //获取该患者的所有传染病
  5768. list, _ := service.GetPatientInfectious(id)
  5769. c.ServeSuccessJSON(map[string]interface{}{
  5770. "patient": patientId,
  5771. "infectioulist": list,
  5772. })
  5773. }
  5774. func (this *DialysisAPIController) GetDialysisSchedule() {
  5775. schedualDate := this.GetString("date")
  5776. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5777. if parseDateErr != nil {
  5778. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5779. return
  5780. }
  5781. adminInfo := this.GetMobileAdminUserInfo()
  5782. orgID := adminInfo.Org.Id
  5783. redis := service.RedisClient()
  5784. defer redis.Close()
  5785. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5786. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5787. if len(scheduals) > 0 {
  5788. //缓存数据
  5789. scheduals_json, err := json.Marshal(scheduals)
  5790. if err == nil {
  5791. redis.Set(key, scheduals_json, time.Second*30)
  5792. }
  5793. }
  5794. this.ServeSuccessJSON(map[string]interface{}{
  5795. "scheduals": scheduals,
  5796. })
  5797. }
  5798. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5799. change_type, _ := this.GetInt64("type", 0)
  5800. record_date := this.GetString("record_time")
  5801. patient_id, _ := this.GetInt64("patient_id", 0)
  5802. timeLayout := "2006-01-02"
  5803. loc, _ := time.LoadLocation("Local")
  5804. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5805. record_time := theAdviceRecordTime.Unix()
  5806. adminUserInfo := this.GetMobileAdminUserInfo()
  5807. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5808. if err == nil {
  5809. if len(advices) == 0 {
  5810. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5811. return
  5812. } else {
  5813. this.ServeSuccessJSON(map[string]interface{}{
  5814. "advices": advices,
  5815. "schedule": sch,
  5816. })
  5817. return
  5818. }
  5819. } else {
  5820. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5821. return
  5822. }
  5823. }
  5824. func (c *DialysisAPIController) CreateConsumables() {
  5825. record_date := c.GetString("record_time")
  5826. patient_id, _ := c.GetInt64("patient_id", 0)
  5827. active, _ := c.GetInt64("active")
  5828. adminUser := c.GetMobileAdminUserInfo()
  5829. timeLayout := "2006-01-02"
  5830. loc, _ := time.LoadLocation("Local")
  5831. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5832. record_time := theRecordTime.Unix()
  5833. // 查询信息规挡的设置天数
  5834. orgid := c.GetMobileAdminUserInfo().Org.Id
  5835. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5836. if infor.ID > 0 {
  5837. var cha_time int64
  5838. timeNowStr := time.Now().Format("2006-01-02")
  5839. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5840. //今日的日期减去设置的日期
  5841. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5842. if cha_time >= record_time {
  5843. //查询审核是否允许
  5844. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5845. //申请状态不允许的情况 拒绝修改
  5846. if infor.ApplicationStatus != 1 {
  5847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5848. return
  5849. }
  5850. }
  5851. }
  5852. dataBody := make(map[string]interface{}, 0)
  5853. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5854. if err != nil {
  5855. utils.ErrorLog(err.Error())
  5856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5857. return
  5858. }
  5859. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5860. var beforePrepares []*models.DialysisBeforePrepareGoods
  5861. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5862. var dialysisBefor []*models.DialysisBeforePrepare
  5863. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5864. goods, _ := dataBody["goods"].([]interface{})
  5865. if len(goods) > 0 {
  5866. for _, item := range goods {
  5867. items := item.(map[string]interface{})
  5868. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5869. utils.ErrorLog("good_id")
  5870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5871. return
  5872. }
  5873. good_id := int64(items["good_id"].(float64))
  5874. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5875. utils.ErrorLog("good_type_id")
  5876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5877. return
  5878. }
  5879. good_type_id := int64(items["good_type_id"].(float64))
  5880. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5881. utils.ErrorLog("count")
  5882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5883. return
  5884. }
  5885. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5886. commdity_code := items["commdity_code"].(string)
  5887. fmt.Println("commdity", commdity_code)
  5888. prepareGoods := &models.DialysisBeforePrepareGoods{
  5889. GoodTypeId: good_type_id,
  5890. GoodId: good_id,
  5891. Count: count,
  5892. StorehouseId: houseConfig.StorehouseOutInfo,
  5893. }
  5894. beforePrepares = append(beforePrepares, prepareGoods)
  5895. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5896. GoodTypeId: good_type_id,
  5897. GoodId: good_id,
  5898. Count: count,
  5899. StorehouseId: houseConfig.StorehouseOutInfo,
  5900. }
  5901. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5902. prepare := &models.DialysisBeforePrepare{
  5903. GoodTypeId: good_type_id,
  5904. GoodId: good_id,
  5905. Count: count,
  5906. PatientId: patient_id,
  5907. RecordDate: record_time,
  5908. UserOrgId: adminUser.Org.Id,
  5909. Status: 1,
  5910. Ctime: time.Now().Unix(),
  5911. Creater: adminUser.AdminUser.Id,
  5912. CommdityCode: commdity_code,
  5913. StorehouseId: houseConfig.StorehouseOutInfo,
  5914. }
  5915. dialysisBefor = append(dialysisBefor, prepare)
  5916. }
  5917. }
  5918. //查询是否有库存
  5919. for _, item := range dialysisBefor {
  5920. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5921. if err == gorm.ErrRecordNotFound {
  5922. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5923. c.ServeSuccessJSON(map[string]interface{}{
  5924. "message": "1",
  5925. "good_name": goodObj.GoodName,
  5926. "specification_name": goodObj.SpecificationName,
  5927. })
  5928. return
  5929. }
  5930. if err != nil {
  5931. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5932. c.ServeSuccessJSON(map[string]interface{}{
  5933. "message": "1",
  5934. "good_name": goodObj.GoodName,
  5935. "specification_name": goodObj.SpecificationName,
  5936. })
  5937. return
  5938. }
  5939. }
  5940. fmt.Println("active-----------------------", active)
  5941. fmt.Println("len(goods)-----------------------", len(goods))
  5942. //新增
  5943. if active == 1 && len(goods) > 0 {
  5944. for _, item := range dialysisBefor {
  5945. dialyPrepareOne := models.DialysisBeforePrepare{
  5946. GoodTypeId: item.GoodTypeId,
  5947. GoodId: item.GoodId,
  5948. PatientId: item.PatientId,
  5949. RecordDate: item.RecordDate,
  5950. UserOrgId: item.UserOrgId,
  5951. Count: item.Count,
  5952. Ctime: time.Now().Unix(),
  5953. Creater: item.Creater,
  5954. CommdityCode: item.CommdityCode,
  5955. Status: 1,
  5956. StorehouseId: houseConfig.StorehouseOutInfo,
  5957. }
  5958. //先清除再插入
  5959. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5960. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5961. //查询默认仓库
  5962. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5963. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5964. var total_count int64
  5965. for _, it := range stockList {
  5966. total_count += it.StockCount
  5967. }
  5968. //基础库插入数据
  5969. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5970. //更新库存
  5971. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5972. var flush_count int64
  5973. for _, it := range goodList {
  5974. flush_count += it.StockCount
  5975. }
  5976. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5977. }
  5978. if err == nil {
  5979. c.ServeSuccessJSON(map[string]interface{}{
  5980. "msg": "保存成功",
  5981. "message": "2",
  5982. })
  5983. return
  5984. } else {
  5985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5986. return
  5987. }
  5988. }
  5989. if len(beforePrepares) > 0 && active == 2 {
  5990. for _, item := range beforePrepares {
  5991. //1.查看该患者该耗材型号最后一次出库数量
  5992. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5993. //判断当前出库数量和最后一次出库数量的大小
  5994. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5995. if item.Count <= goodInfo.Count {
  5996. //退库
  5997. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5998. //查询今日出库数据
  5999. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6000. for _, it := range list {
  6001. prepare := models.DialysisBeforePrepare{
  6002. UserOrgId: it.OrgId,
  6003. PatientId: patient_id,
  6004. RecordDate: it.RecordTime,
  6005. GoodId: it.GoodId,
  6006. GoodTypeId: it.GoodTypeId,
  6007. Count: it.Count,
  6008. Ctime: time.Now().Unix(),
  6009. Creater: adminUser.AdminUser.Id,
  6010. Status: 1,
  6011. StorehouseId: houseConfig.StorehouseOutInfo,
  6012. }
  6013. //删除准备表数据
  6014. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6015. service.CreateDialysisBeforePrepareOne(&prepare)
  6016. }
  6017. }
  6018. var last_total int64
  6019. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6020. if item.Count >= goodInfo.Count {
  6021. //查询当前批次当前耗材最后一条出库数据
  6022. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6023. //计算当前出库和最后一次出库数据相差数据
  6024. last_total = item.Count - lastOutInfo.Count
  6025. //查询该批次剩余库存
  6026. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6027. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6028. if lastInfo.StockCount >= last_total {
  6029. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6030. //查询今日出库数据
  6031. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6032. for _, it := range list {
  6033. prepare := models.DialysisBeforePrepare{
  6034. UserOrgId: it.OrgId,
  6035. PatientId: patient_id,
  6036. RecordDate: it.RecordTime,
  6037. GoodId: it.GoodId,
  6038. GoodTypeId: it.GoodTypeId,
  6039. Count: it.Count,
  6040. Ctime: time.Now().Unix(),
  6041. Creater: adminUser.AdminUser.Id,
  6042. Status: 1,
  6043. StorehouseId: houseConfig.StorehouseOutInfo,
  6044. }
  6045. //删除准备表数据
  6046. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6047. service.CreateDialysisBeforePrepareOne(&prepare)
  6048. //查询默认仓库
  6049. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6050. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6051. var total_count int64
  6052. for _, it := range stockList {
  6053. total_count += it.StockCount
  6054. }
  6055. //基础库插入数据
  6056. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6057. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6058. var flush_count int64
  6059. for _, it := range goodList {
  6060. flush_count += it.StockCount
  6061. }
  6062. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6063. }
  6064. }
  6065. //如果库存不够,则出库到下一个批次
  6066. if lastInfo.StockCount < last_total {
  6067. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6068. //查询今日出库数据
  6069. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6070. for _, it := range list {
  6071. prepare := models.DialysisBeforePrepare{
  6072. UserOrgId: it.OrgId,
  6073. PatientId: patient_id,
  6074. RecordDate: it.RecordTime,
  6075. GoodId: it.GoodId,
  6076. GoodTypeId: it.GoodTypeId,
  6077. Count: it.Count,
  6078. Ctime: time.Now().Unix(),
  6079. Creater: adminUser.AdminUser.Id,
  6080. Status: 1,
  6081. StorehouseId: houseConfig.StorehouseOutInfo,
  6082. }
  6083. //删除准备表数据
  6084. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6085. service.CreateDialysisBeforePrepareOne(&prepare)
  6086. //查询默认仓库
  6087. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6088. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6089. var total_count int64
  6090. for _, it := range stockList {
  6091. total_count += it.StockCount
  6092. }
  6093. //基础库插入数据
  6094. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6095. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6096. var flush_count int64
  6097. for _, it := range goodList {
  6098. flush_count += it.StockCount
  6099. }
  6100. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6101. }
  6102. if err != nil {
  6103. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6104. c.ServeSuccessJSON(map[string]interface{}{
  6105. "message": "1",
  6106. "good_name": goodObj.GoodName,
  6107. "specification_name": goodObj.SpecificationName,
  6108. })
  6109. return
  6110. }
  6111. }
  6112. }
  6113. if err != nil {
  6114. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6115. c.ServeSuccessJSON(map[string]interface{}{
  6116. "message": "1",
  6117. "good_name": goodObj.GoodName,
  6118. "specification_name": goodObj.SpecificationName,
  6119. })
  6120. return
  6121. }
  6122. }
  6123. }
  6124. }
  6125. var errs error
  6126. if errs == nil {
  6127. c.ServeSuccessJSON(map[string]interface{}{
  6128. "msg": "提交成功",
  6129. "message": "2",
  6130. "good_name": "",
  6131. "specification_name": "",
  6132. })
  6133. return
  6134. } else {
  6135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6136. return
  6137. }
  6138. }
  6139. func (c *DialysisAPIController) CreateStockOutInfo() {
  6140. patient_id, _ := c.GetInt64("patient_id", 0)
  6141. record_date := c.GetString("record_time")
  6142. if patient_id <= 0 {
  6143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6144. return
  6145. }
  6146. adminInfo := c.GetMobileAdminUserInfo()
  6147. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6148. timeLayout := "2006-01-02"
  6149. loc, _ := time.LoadLocation("Local")
  6150. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6151. record_time := theRecordTime.Unix()
  6152. // 查询信息规挡的设置天数
  6153. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6154. if infor.ID > 0 && infor.WeekDay > 0 {
  6155. var cha_time int64
  6156. timeNowStr := time.Now().Format("2006-01-02")
  6157. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6158. //今日的日期减去设置的日期
  6159. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6160. if cha_time >= record_time {
  6161. //查询审核是否允许
  6162. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6163. //申请状态不允许的情况 拒绝修改
  6164. if infor.ApplicationStatus != 1 {
  6165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6166. return
  6167. }
  6168. }
  6169. }
  6170. //创建步骤表
  6171. finish := models.XtDialysisFinish{
  6172. IsFinish: 1,
  6173. UserOrgId: adminInfo.Org.Id,
  6174. Status: 1,
  6175. Ctime: time.Now().Unix(),
  6176. Mtime: 0,
  6177. Module: 11,
  6178. RecordDate: record_time,
  6179. Sourse: 1,
  6180. PatientId: patient_id,
  6181. }
  6182. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6183. if dialysisFinish.ID == 0 {
  6184. service.CreateDialysisFinish(finish)
  6185. }
  6186. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6187. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6188. //去重
  6189. consumables = RemoveRepeatedGood(consumables)
  6190. if adminInfo.Org.Id == 9919 {
  6191. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6192. //查询是否有库存
  6193. for _, item := range consumables {
  6194. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6195. if item.Count > warehouse.Count {
  6196. goodErrcode := models.XtGoodErrcode{
  6197. UserOrgId: item.UserOrgId,
  6198. Errcode: "自动出库库存不足",
  6199. GoodId: item.GoodId,
  6200. Status: 1,
  6201. Ctime: time.Now().Unix(),
  6202. Mtime: 0,
  6203. Count: 0,
  6204. StockCount: 0,
  6205. Creater: creator,
  6206. BatchNumberId: warehouse.ID,
  6207. WarehouseOutId: 0,
  6208. }
  6209. service.CreateGoodErrcode(goodErrcode)
  6210. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6211. c.ServeSuccessJSON(map[string]interface{}{
  6212. "message": "1",
  6213. "good_name": goodObj.GoodName,
  6214. "specification_name": goodObj.SpecificationName,
  6215. })
  6216. return
  6217. }
  6218. }
  6219. //查询是否有出库单
  6220. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6221. if err == gorm.ErrRecordNotFound {
  6222. //没有记录,则创建出库单
  6223. timeStr := time.Now().Format("2006-01-02")
  6224. timeArr := strings.Split(timeStr, "-")
  6225. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6226. total = total + 1
  6227. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6228. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6229. number = number + total
  6230. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6231. creater := adminInfo.AdminUser.Id
  6232. warehouseOut := models.WarehouseOut{
  6233. WarehouseOutOrderNumber: warehousing_out_order,
  6234. OperationTime: time.Now().Unix(),
  6235. OrgId: adminInfo.Org.Id,
  6236. Creater: creater,
  6237. Ctime: time.Now().Unix(),
  6238. Status: 1,
  6239. WarehouseOutTime: record_time,
  6240. Dealer: 0,
  6241. Manufacturer: 0,
  6242. Type: 1,
  6243. IsSys: 1,
  6244. StorehouseId: houseConfig.StorehouseOutInfo,
  6245. IsCheck: 1,
  6246. }
  6247. err := service.AddSigleWarehouseOut(&warehouseOut)
  6248. if err != nil {
  6249. goodErrcode := models.XtGoodErrcode{
  6250. UserOrgId: adminInfo.Org.Id,
  6251. Errcode: "创建出库单失败",
  6252. GoodId: 0,
  6253. Status: 1,
  6254. Ctime: time.Now().Unix(),
  6255. Mtime: 0,
  6256. Count: 0,
  6257. StockCount: 0,
  6258. Creater: creator,
  6259. BatchNumberId: 0,
  6260. WarehouseOutId: 0,
  6261. }
  6262. service.CreateGoodErrcode(goodErrcode)
  6263. utils.TraceLog("创建出库单失败 err = %v", err)
  6264. } else {
  6265. for _, item := range consumables {
  6266. //出库
  6267. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6268. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6269. if err == nil {
  6270. goodErrcode := models.XtGoodErrcode{
  6271. UserOrgId: adminInfo.Org.Id,
  6272. Errcode: "自动出库接口报错",
  6273. GoodId: 0,
  6274. Status: 1,
  6275. Ctime: time.Now().Unix(),
  6276. Mtime: 0,
  6277. Count: 0,
  6278. StockCount: 0,
  6279. Creater: creator,
  6280. BatchNumberId: 0,
  6281. WarehouseOutId: 0,
  6282. }
  6283. service.CreateGoodErrcode(goodErrcode)
  6284. utils.TraceLog("创建出库单失败 err = %v", err)
  6285. }
  6286. //查询
  6287. //出库数量相加
  6288. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6289. if errs != nil {
  6290. goodErrcode := models.XtGoodErrcode{
  6291. UserOrgId: item.UserOrgId,
  6292. Errcode: "创建剩余库存字段报错",
  6293. GoodId: item.GoodId,
  6294. Status: 1,
  6295. Ctime: time.Now().Unix(),
  6296. Mtime: 0,
  6297. Count: 0,
  6298. StockCount: 0,
  6299. Creater: creater,
  6300. BatchNumberId: 0,
  6301. WarehouseOutId: 0,
  6302. }
  6303. service.CreateGoodErrcode(goodErrcode)
  6304. }
  6305. }
  6306. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6307. if len(list) == 0 {
  6308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6309. return
  6310. }
  6311. for _, item := range list {
  6312. prepare := models.DialysisBeforePrepare{
  6313. UserOrgId: adminInfo.Org.Id,
  6314. PatientId: patient_id,
  6315. RecordDate: record_time,
  6316. GoodId: item.GoodId,
  6317. GoodTypeId: item.GoodTypeId,
  6318. Count: item.Count,
  6319. Creater: adminInfo.AdminUser.Id,
  6320. Status: 1,
  6321. Ctime: time.Now().Unix(),
  6322. StorehouseId: houseConfig.StorehouseOutInfo,
  6323. }
  6324. //清空准备表数据
  6325. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6326. if err != nil {
  6327. goodErrcode := models.XtGoodErrcode{
  6328. UserOrgId: item.OrgId,
  6329. Errcode: "自动出库清空准备表数据报错",
  6330. GoodId: item.GoodId,
  6331. Status: 1,
  6332. Ctime: time.Now().Unix(),
  6333. Mtime: 0,
  6334. Count: 0,
  6335. StockCount: 0,
  6336. Creater: creater,
  6337. BatchNumberId: 0,
  6338. WarehouseOutId: 0,
  6339. }
  6340. service.CreateGoodErrcode(goodErrcode)
  6341. }
  6342. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6343. if errs != nil {
  6344. goodErrcode := models.XtGoodErrcode{
  6345. UserOrgId: item.OrgId,
  6346. Errcode: "自动出库创建准备表数据报错",
  6347. GoodId: item.GoodId,
  6348. Status: 1,
  6349. Ctime: time.Now().Unix(),
  6350. Mtime: 0,
  6351. Count: 0,
  6352. StockCount: 0,
  6353. Creater: creater,
  6354. BatchNumberId: 0,
  6355. WarehouseOutId: 0,
  6356. }
  6357. service.CreateGoodErrcode(goodErrcode)
  6358. }
  6359. //查询默认仓库
  6360. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6361. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6362. var total_count int64
  6363. for _, it := range stockList {
  6364. total_count += it.StockCount
  6365. }
  6366. //基础库插入数据
  6367. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6368. if errcodes != nil {
  6369. goodErrcode := models.XtGoodErrcode{
  6370. UserOrgId: item.OrgId,
  6371. Errcode: "自动出库基础库插入数据",
  6372. GoodId: item.GoodId,
  6373. Status: 1,
  6374. Ctime: time.Now().Unix(),
  6375. Mtime: 0,
  6376. Count: 0,
  6377. StockCount: 0,
  6378. Creater: creater,
  6379. BatchNumberId: 0,
  6380. WarehouseOutId: 0,
  6381. }
  6382. service.CreateGoodErrcode(goodErrcode)
  6383. }
  6384. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6385. var flush_count int64
  6386. for _, it := range goodList {
  6387. flush_count += it.StockCount
  6388. }
  6389. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6390. if errsss != nil {
  6391. goodErrcode := models.XtGoodErrcode{
  6392. UserOrgId: item.OrgId,
  6393. Errcode: "自动出库剩余库存更新数据",
  6394. GoodId: item.GoodId,
  6395. Status: 1,
  6396. Ctime: time.Now().Unix(),
  6397. Mtime: 0,
  6398. Count: 0,
  6399. StockCount: 0,
  6400. Creater: creater,
  6401. BatchNumberId: 0,
  6402. WarehouseOutId: 0,
  6403. }
  6404. service.CreateGoodErrcode(goodErrcode)
  6405. }
  6406. }
  6407. }
  6408. //
  6409. } else if err == nil {
  6410. for _, item := range consumables {
  6411. //出库
  6412. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6413. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6414. if err != nil {
  6415. goodErrcode := models.XtGoodErrcode{
  6416. UserOrgId: adminInfo.Org.Id,
  6417. Errcode: "自动出库接口报错",
  6418. GoodId: 0,
  6419. Status: 1,
  6420. Ctime: time.Now().Unix(),
  6421. Mtime: 0,
  6422. Count: 0,
  6423. StockCount: 0,
  6424. Creater: creator,
  6425. BatchNumberId: 0,
  6426. WarehouseOutId: 0,
  6427. }
  6428. service.CreateGoodErrcode(goodErrcode)
  6429. }
  6430. //出库数量相加
  6431. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6432. if errss != nil {
  6433. goodErrcode := models.XtGoodErrcode{
  6434. UserOrgId: item.UserOrgId,
  6435. Errcode: "创建剩余库存字段报错",
  6436. GoodId: item.GoodId,
  6437. Status: 1,
  6438. Ctime: time.Now().Unix(),
  6439. Mtime: time.Now().Unix(),
  6440. Count: 0,
  6441. StockCount: 0,
  6442. Creater: item.Creater,
  6443. BatchNumberId: 0,
  6444. WarehouseOutId: 0,
  6445. }
  6446. service.CreateGoodErrcode(goodErrcode)
  6447. }
  6448. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6449. if len(list) == 0 {
  6450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6451. return
  6452. }
  6453. for _, item := range list {
  6454. prepare := models.DialysisBeforePrepare{
  6455. UserOrgId: adminInfo.Org.Id,
  6456. PatientId: patient_id,
  6457. RecordDate: record_time,
  6458. GoodId: item.GoodId,
  6459. GoodTypeId: item.GoodTypeId,
  6460. Count: item.Count,
  6461. Creater: adminInfo.AdminUser.Id,
  6462. Status: 1,
  6463. Ctime: time.Now().Unix(),
  6464. StorehouseId: houseConfig.StorehouseOutInfo,
  6465. }
  6466. //清空准备表数据
  6467. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6468. if errs != nil {
  6469. goodErrcode := models.XtGoodErrcode{
  6470. UserOrgId: adminInfo.Org.Id,
  6471. Errcode: "自动出库清空准备表数据报错",
  6472. GoodId: 0,
  6473. Status: 1,
  6474. Ctime: time.Now().Unix(),
  6475. Mtime: 0,
  6476. Count: 0,
  6477. StockCount: 0,
  6478. Creater: creator,
  6479. BatchNumberId: 0,
  6480. WarehouseOutId: 0,
  6481. }
  6482. service.CreateGoodErrcode(goodErrcode)
  6483. }
  6484. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6485. if errcodes != nil {
  6486. goodErrcode := models.XtGoodErrcode{
  6487. UserOrgId: adminInfo.Org.Id,
  6488. Errcode: "自动出库创建准备表数据报错",
  6489. GoodId: 0,
  6490. Status: 1,
  6491. Ctime: time.Now().Unix(),
  6492. Mtime: 0,
  6493. Count: 0,
  6494. StockCount: 0,
  6495. Creater: creator,
  6496. BatchNumberId: 0,
  6497. WarehouseOutId: 0,
  6498. }
  6499. service.CreateGoodErrcode(goodErrcode)
  6500. }
  6501. //查询默认仓库
  6502. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6503. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6504. var total_count int64
  6505. for _, it := range stockList {
  6506. total_count += it.StockCount
  6507. }
  6508. //基础库插入数据
  6509. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6510. if errcodes != nil {
  6511. goodErrcode := models.XtGoodErrcode{
  6512. UserOrgId: adminInfo.Org.Id,
  6513. Errcode: "自动出库基础库插入数据报错",
  6514. GoodId: 0,
  6515. Status: 1,
  6516. Ctime: time.Now().Unix(),
  6517. Mtime: 0,
  6518. Count: 0,
  6519. StockCount: 0,
  6520. Creater: creator,
  6521. BatchNumberId: 0,
  6522. WarehouseOutId: 0,
  6523. }
  6524. service.CreateGoodErrcode(goodErrcode)
  6525. }
  6526. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6527. var flush_count int64
  6528. for _, it := range goodList {
  6529. flush_count += it.StockCount
  6530. }
  6531. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6532. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6533. if errss != nil {
  6534. goodErrcode := models.XtGoodErrcode{
  6535. UserOrgId: item.OrgId,
  6536. Errcode: "自动出库剩余库存更新数据",
  6537. GoodId: item.GoodId,
  6538. Status: 1,
  6539. Ctime: time.Now().Unix(),
  6540. Mtime: 0,
  6541. Count: 0,
  6542. StockCount: 0,
  6543. Creater: creater,
  6544. BatchNumberId: 0,
  6545. WarehouseOutId: 0,
  6546. }
  6547. service.CreateGoodErrcode(goodErrcode)
  6548. }
  6549. }
  6550. }
  6551. }
  6552. c.ServeSuccessJSON(map[string]interface{}{
  6553. "msg": "提交成功",
  6554. "message": "2",
  6555. "good_name": "",
  6556. "specification_name": "",
  6557. })
  6558. return
  6559. }
  6560. if record.IsOpen == 1 {
  6561. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6562. //查询是否有库存
  6563. for _, item := range consumables {
  6564. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6565. if item.Count > warehouse.Count {
  6566. goodErrcode := models.XtGoodErrcode{
  6567. UserOrgId: item.UserOrgId,
  6568. Errcode: "自动出库库存不足",
  6569. GoodId: item.GoodId,
  6570. Status: 1,
  6571. Ctime: time.Now().Unix(),
  6572. Mtime: 0,
  6573. Count: 0,
  6574. StockCount: 0,
  6575. Creater: creator,
  6576. BatchNumberId: warehouse.ID,
  6577. WarehouseOutId: 0,
  6578. }
  6579. service.CreateGoodErrcode(goodErrcode)
  6580. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6581. c.ServeSuccessJSON(map[string]interface{}{
  6582. "message": "1",
  6583. "good_name": goodObj.GoodName,
  6584. "specification_name": goodObj.SpecificationName,
  6585. })
  6586. return
  6587. }
  6588. }
  6589. //查询是否有出库单
  6590. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6591. if err == gorm.ErrRecordNotFound {
  6592. //没有记录,则创建出库单
  6593. timeStr := time.Now().Format("2006-01-02")
  6594. timeArr := strings.Split(timeStr, "-")
  6595. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6596. total = total + 1
  6597. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6598. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6599. number = number + total
  6600. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6601. creater := adminInfo.AdminUser.Id
  6602. warehouseOut := models.WarehouseOut{
  6603. WarehouseOutOrderNumber: warehousing_out_order,
  6604. OperationTime: time.Now().Unix(),
  6605. OrgId: adminInfo.Org.Id,
  6606. Creater: creater,
  6607. Ctime: time.Now().Unix(),
  6608. Status: 1,
  6609. WarehouseOutTime: record_time,
  6610. Dealer: 0,
  6611. Manufacturer: 0,
  6612. Type: 1,
  6613. IsSys: 1,
  6614. StorehouseId: houseConfig.StorehouseOutInfo,
  6615. IsCheck: 1,
  6616. }
  6617. err := service.AddSigleWarehouseOut(&warehouseOut)
  6618. if err != nil {
  6619. goodErrcode := models.XtGoodErrcode{
  6620. UserOrgId: adminInfo.Org.Id,
  6621. Errcode: "创建出库单失败",
  6622. GoodId: 0,
  6623. Status: 1,
  6624. Ctime: time.Now().Unix(),
  6625. Mtime: 0,
  6626. Count: 0,
  6627. StockCount: 0,
  6628. Creater: creator,
  6629. BatchNumberId: 0,
  6630. WarehouseOutId: 0,
  6631. }
  6632. service.CreateGoodErrcode(goodErrcode)
  6633. utils.TraceLog("创建出库单失败 err = %v", err)
  6634. } else {
  6635. for _, item := range consumables {
  6636. //出库
  6637. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6638. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6639. if err == nil {
  6640. goodErrcode := models.XtGoodErrcode{
  6641. UserOrgId: adminInfo.Org.Id,
  6642. Errcode: "自动出库接口报错",
  6643. GoodId: 0,
  6644. Status: 1,
  6645. Ctime: time.Now().Unix(),
  6646. Mtime: 0,
  6647. Count: 0,
  6648. StockCount: 0,
  6649. Creater: creator,
  6650. BatchNumberId: 0,
  6651. WarehouseOutId: 0,
  6652. }
  6653. service.CreateGoodErrcode(goodErrcode)
  6654. utils.TraceLog("创建出库单失败 err = %v", err)
  6655. }
  6656. //查询
  6657. //出库数量相加
  6658. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6659. if errs != nil {
  6660. goodErrcode := models.XtGoodErrcode{
  6661. UserOrgId: item.UserOrgId,
  6662. Errcode: "创建剩余库存字段报错",
  6663. GoodId: item.GoodId,
  6664. Status: 1,
  6665. Ctime: time.Now().Unix(),
  6666. Mtime: 0,
  6667. Count: 0,
  6668. StockCount: 0,
  6669. Creater: creater,
  6670. BatchNumberId: 0,
  6671. WarehouseOutId: 0,
  6672. }
  6673. service.CreateGoodErrcode(goodErrcode)
  6674. }
  6675. }
  6676. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6677. if len(list) == 0 {
  6678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6679. return
  6680. }
  6681. for _, item := range list {
  6682. prepare := models.DialysisBeforePrepare{
  6683. UserOrgId: adminInfo.Org.Id,
  6684. PatientId: patient_id,
  6685. RecordDate: record_time,
  6686. GoodId: item.GoodId,
  6687. GoodTypeId: item.GoodTypeId,
  6688. Count: item.Count,
  6689. Creater: adminInfo.AdminUser.Id,
  6690. Status: 1,
  6691. Ctime: time.Now().Unix(),
  6692. StorehouseId: houseConfig.StorehouseOutInfo,
  6693. }
  6694. //清空准备表数据
  6695. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6696. if err != nil {
  6697. goodErrcode := models.XtGoodErrcode{
  6698. UserOrgId: item.OrgId,
  6699. Errcode: "自动出库清空准备表数据报错",
  6700. GoodId: item.GoodId,
  6701. Status: 1,
  6702. Ctime: time.Now().Unix(),
  6703. Mtime: 0,
  6704. Count: 0,
  6705. StockCount: 0,
  6706. Creater: creater,
  6707. BatchNumberId: 0,
  6708. WarehouseOutId: 0,
  6709. }
  6710. service.CreateGoodErrcode(goodErrcode)
  6711. }
  6712. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6713. if errs != nil {
  6714. goodErrcode := models.XtGoodErrcode{
  6715. UserOrgId: item.OrgId,
  6716. Errcode: "自动出库创建准备表数据报错",
  6717. GoodId: item.GoodId,
  6718. Status: 1,
  6719. Ctime: time.Now().Unix(),
  6720. Mtime: 0,
  6721. Count: 0,
  6722. StockCount: 0,
  6723. Creater: creater,
  6724. BatchNumberId: 0,
  6725. WarehouseOutId: 0,
  6726. }
  6727. service.CreateGoodErrcode(goodErrcode)
  6728. }
  6729. //查询默认仓库
  6730. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6731. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6732. var total_count int64
  6733. for _, it := range stockList {
  6734. total_count += it.StockCount
  6735. }
  6736. //基础库插入数据
  6737. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6738. if errcodes != nil {
  6739. goodErrcode := models.XtGoodErrcode{
  6740. UserOrgId: item.OrgId,
  6741. Errcode: "自动出库基础库插入数据",
  6742. GoodId: item.GoodId,
  6743. Status: 1,
  6744. Ctime: time.Now().Unix(),
  6745. Mtime: 0,
  6746. Count: 0,
  6747. StockCount: 0,
  6748. Creater: creater,
  6749. BatchNumberId: 0,
  6750. WarehouseOutId: 0,
  6751. }
  6752. service.CreateGoodErrcode(goodErrcode)
  6753. }
  6754. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6755. var flush_count int64
  6756. for _, it := range goodList {
  6757. flush_count += it.StockCount
  6758. }
  6759. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6760. if errsss != nil {
  6761. goodErrcode := models.XtGoodErrcode{
  6762. UserOrgId: item.OrgId,
  6763. Errcode: "自动出库剩余库存更新数据",
  6764. GoodId: item.GoodId,
  6765. Status: 1,
  6766. Ctime: time.Now().Unix(),
  6767. Mtime: 0,
  6768. Count: 0,
  6769. StockCount: 0,
  6770. Creater: creater,
  6771. BatchNumberId: 0,
  6772. WarehouseOutId: 0,
  6773. }
  6774. service.CreateGoodErrcode(goodErrcode)
  6775. }
  6776. }
  6777. }
  6778. //
  6779. } else if err == nil {
  6780. for _, item := range consumables {
  6781. //出库
  6782. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6783. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6784. if err != nil {
  6785. goodErrcode := models.XtGoodErrcode{
  6786. UserOrgId: adminInfo.Org.Id,
  6787. Errcode: "自动出库接口报错",
  6788. GoodId: 0,
  6789. Status: 1,
  6790. Ctime: time.Now().Unix(),
  6791. Mtime: 0,
  6792. Count: 0,
  6793. StockCount: 0,
  6794. Creater: creator,
  6795. BatchNumberId: 0,
  6796. WarehouseOutId: 0,
  6797. }
  6798. service.CreateGoodErrcode(goodErrcode)
  6799. }
  6800. //出库数量相加
  6801. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6802. if errss != nil {
  6803. goodErrcode := models.XtGoodErrcode{
  6804. UserOrgId: item.UserOrgId,
  6805. Errcode: "创建剩余库存字段报错",
  6806. GoodId: item.GoodId,
  6807. Status: 1,
  6808. Ctime: time.Now().Unix(),
  6809. Mtime: time.Now().Unix(),
  6810. Count: 0,
  6811. StockCount: 0,
  6812. Creater: item.Creater,
  6813. BatchNumberId: 0,
  6814. WarehouseOutId: 0,
  6815. }
  6816. service.CreateGoodErrcode(goodErrcode)
  6817. }
  6818. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6819. if len(list) == 0 {
  6820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6821. return
  6822. }
  6823. for _, item := range list {
  6824. prepare := models.DialysisBeforePrepare{
  6825. UserOrgId: adminInfo.Org.Id,
  6826. PatientId: patient_id,
  6827. RecordDate: record_time,
  6828. GoodId: item.GoodId,
  6829. GoodTypeId: item.GoodTypeId,
  6830. Count: item.Count,
  6831. Creater: adminInfo.AdminUser.Id,
  6832. Status: 1,
  6833. Ctime: time.Now().Unix(),
  6834. StorehouseId: houseConfig.StorehouseOutInfo,
  6835. }
  6836. //清空准备表数据
  6837. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6838. if errs != nil {
  6839. goodErrcode := models.XtGoodErrcode{
  6840. UserOrgId: adminInfo.Org.Id,
  6841. Errcode: "自动出库清空准备表数据报错",
  6842. GoodId: 0,
  6843. Status: 1,
  6844. Ctime: time.Now().Unix(),
  6845. Mtime: 0,
  6846. Count: 0,
  6847. StockCount: 0,
  6848. Creater: creator,
  6849. BatchNumberId: 0,
  6850. WarehouseOutId: 0,
  6851. }
  6852. service.CreateGoodErrcode(goodErrcode)
  6853. }
  6854. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6855. if errcodes != nil {
  6856. goodErrcode := models.XtGoodErrcode{
  6857. UserOrgId: adminInfo.Org.Id,
  6858. Errcode: "自动出库创建准备表数据报错",
  6859. GoodId: 0,
  6860. Status: 1,
  6861. Ctime: time.Now().Unix(),
  6862. Mtime: 0,
  6863. Count: 0,
  6864. StockCount: 0,
  6865. Creater: creator,
  6866. BatchNumberId: 0,
  6867. WarehouseOutId: 0,
  6868. }
  6869. service.CreateGoodErrcode(goodErrcode)
  6870. }
  6871. //查询默认仓库
  6872. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6873. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6874. var total_count int64
  6875. for _, it := range stockList {
  6876. total_count += it.StockCount
  6877. }
  6878. //基础库插入数据
  6879. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6880. if errcodes != nil {
  6881. goodErrcode := models.XtGoodErrcode{
  6882. UserOrgId: adminInfo.Org.Id,
  6883. Errcode: "自动出库基础库插入数据报错",
  6884. GoodId: 0,
  6885. Status: 1,
  6886. Ctime: time.Now().Unix(),
  6887. Mtime: 0,
  6888. Count: 0,
  6889. StockCount: 0,
  6890. Creater: creator,
  6891. BatchNumberId: 0,
  6892. WarehouseOutId: 0,
  6893. }
  6894. service.CreateGoodErrcode(goodErrcode)
  6895. }
  6896. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6897. var flush_count int64
  6898. for _, it := range goodList {
  6899. flush_count += it.StockCount
  6900. }
  6901. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6902. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6903. if errss != nil {
  6904. goodErrcode := models.XtGoodErrcode{
  6905. UserOrgId: item.OrgId,
  6906. Errcode: "自动出库剩余库存更新数据",
  6907. GoodId: item.GoodId,
  6908. Status: 1,
  6909. Ctime: time.Now().Unix(),
  6910. Mtime: 0,
  6911. Count: 0,
  6912. StockCount: 0,
  6913. Creater: creater,
  6914. BatchNumberId: 0,
  6915. WarehouseOutId: 0,
  6916. }
  6917. service.CreateGoodErrcode(goodErrcode)
  6918. }
  6919. }
  6920. }
  6921. }
  6922. c.ServeSuccessJSON(map[string]interface{}{
  6923. "msg": "提交成功",
  6924. "message": "2",
  6925. "good_name": "",
  6926. "specification_name": "",
  6927. })
  6928. return
  6929. } else {
  6930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6931. return
  6932. }
  6933. }
  6934. func (c *DialysisAPIController) EditConsumables() {
  6935. patient_id, _ := c.GetInt64("patient_id", 0)
  6936. record_date := c.GetString("record_time")
  6937. if patient_id <= 0 {
  6938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6939. return
  6940. }
  6941. adminInfo := c.GetMobileAdminUserInfo()
  6942. timeLayout := "2006-01-02"
  6943. loc, _ := time.LoadLocation("Local")
  6944. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6945. record_time := theRecordTime.Unix()
  6946. // 查询信息规挡的设置天数
  6947. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6948. if infor.ID > 0 && infor.WeekDay > 0 {
  6949. var cha_time int64
  6950. timeNowStr := time.Now().Format("2006-01-02")
  6951. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6952. //今日的日期减去设置的日期
  6953. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6954. if cha_time >= record_time {
  6955. //查询审核是否允许
  6956. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6957. //申请状态不允许的情况 拒绝修改
  6958. if infor.ApplicationStatus != 1 {
  6959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6960. return
  6961. }
  6962. }
  6963. }
  6964. dataBody := make(map[string]interface{}, 0)
  6965. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6966. if err != nil {
  6967. utils.ErrorLog(err.Error())
  6968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6969. return
  6970. }
  6971. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6972. var beforePrepares []*models.DialysisBeforePrepareGoods
  6973. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6974. var cancelbefor []*models.DialysisBeforePrepareGoods
  6975. var outbefor []*models.DialysisBeforePrepareGoods
  6976. //判断是否开启自动出库
  6977. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6978. if record.IsOpen == 1 {
  6979. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6980. goods, _ := dataBody["goods"].([]interface{})
  6981. if len(goods) > 0 {
  6982. for _, item := range goods {
  6983. items := item.(map[string]interface{})
  6984. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6985. utils.ErrorLog("good_id")
  6986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6987. return
  6988. }
  6989. good_id := int64(items["good_id"].(float64))
  6990. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6991. utils.ErrorLog("good_type_id")
  6992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6993. return
  6994. }
  6995. good_type_id := int64(items["good_type_id"].(float64))
  6996. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6997. utils.ErrorLog("count")
  6998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6999. return
  7000. }
  7001. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7002. commdity_code := items["commdity_code"].(string)
  7003. fmt.Println(commdity_code)
  7004. prepareGoods := &models.DialysisBeforePrepareGoods{
  7005. GoodTypeId: good_type_id,
  7006. GoodId: good_id,
  7007. Count: count,
  7008. StorehouseId: houseConfig.StorehouseOutInfo,
  7009. }
  7010. beforePrepares = append(beforePrepares, prepareGoods)
  7011. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7012. GoodTypeId: good_type_id,
  7013. GoodId: good_id,
  7014. Count: count,
  7015. StorehouseId: houseConfig.StorehouseOutInfo,
  7016. }
  7017. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7018. }
  7019. for _, item := range beforePrepares {
  7020. //1.查看该患者该耗材型号最后一次出库数量
  7021. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7022. //判断当前出库数量和最后一次出库数量的大小
  7023. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7024. if item.Count < goodInfo.Count {
  7025. cancelbefor = append(cancelbefor, item)
  7026. }
  7027. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7028. if item.Count > goodInfo.Count {
  7029. outbefor = append(outbefor, item)
  7030. }
  7031. //处理编辑耗材新增不了的问题
  7032. if goodInfo.Count == item.Count {
  7033. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7034. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7035. }
  7036. }
  7037. if len(cancelbefor) > 0 {
  7038. //退库
  7039. for _, item := range cancelbefor {
  7040. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7041. creater := adminInfo.AdminUser.Id
  7042. //查询该患者当天已经出库的耗材信息
  7043. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7044. var delete_count int64 = 0
  7045. delete_count = warehouseOutInfos.Count - item.Count
  7046. //增加库存数量
  7047. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7048. //减少实际出库库存数量
  7049. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7050. // 删除出库完成后,要增加对应批次的库存数量
  7051. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7052. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7053. //更新剩余库存
  7054. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7055. var flush_count int64
  7056. for _, it := range goodListOne {
  7057. flush_count += it.StockCount
  7058. }
  7059. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7060. //查询剩余库存
  7061. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7062. var sum_count int64
  7063. for _, item := range goodList {
  7064. sum_count += item.StockCount
  7065. }
  7066. // 在出库记录表里记录退库详情
  7067. warehouseOutInfo := &models.WarehouseOutInfo{
  7068. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7069. WarehouseOutId: warehouseOut.ID,
  7070. Status: 1,
  7071. Ctime: time.Now().Unix(),
  7072. OrgId: adminInfo.Org.Id,
  7073. Type: 1,
  7074. IsSys: 1,
  7075. SysRecordTime: record_time,
  7076. GoodTypeId: item.GoodTypeId,
  7077. GoodId: item.GoodId,
  7078. PatientId: patient_id,
  7079. ConsumableType: 2,
  7080. StorehouseId: houseConfig.StorehouseOutInfo,
  7081. IsCheck: 1,
  7082. OverCount: sum_count,
  7083. }
  7084. warehouseOutInfo.Count = item.Count
  7085. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7086. warehouseOutInfo.Price = stockInInfo.Price
  7087. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7088. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7089. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7090. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7091. warehouseOutInfo.Number = warehouseOutInfos.Number
  7092. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7093. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7094. //查找当天是否存在出库记录
  7095. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7096. if errcod == gorm.ErrRecordNotFound {
  7097. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7098. //插入详情明细表
  7099. stockFlow := models.VmStockFlow{
  7100. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7101. WarehouseOutId: warehouseOut.ID,
  7102. GoodId: item.GoodId,
  7103. Number: warehouseOutInfos.Number,
  7104. ProductDate: stockInInfo.ProductDate,
  7105. ExpireDate: stockInInfo.ExpiryDate,
  7106. Count: item.Count,
  7107. Price: stockInInfo.Price,
  7108. Status: 1,
  7109. Ctime: record_time,
  7110. UserOrgId: adminInfo.Org.Id,
  7111. Manufacturer: stockInInfo.Manufacturer,
  7112. Dealer: stockInInfo.Dealer,
  7113. LicenseNumber: stockInInfo.LicenseNumber,
  7114. IsEdit: 2,
  7115. Creator: creater,
  7116. SystemTime: record_time,
  7117. ConsumableType: 3,
  7118. WarehousingDetailId: 0,
  7119. IsSys: 1,
  7120. UpdateCreator: creater,
  7121. PatientId: patient_id,
  7122. StorehouseId: houseConfig.StorehouseOutInfo,
  7123. }
  7124. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7125. if errflow == gorm.ErrRecordNotFound {
  7126. //创建流水表
  7127. err := service.CreateStockFlowOne(stockFlow)
  7128. fmt.Println("err", err)
  7129. } else if errflow == nil {
  7130. //插入详情明细表
  7131. stockFlow := models.VmStockFlow{
  7132. ID: exsit.ID,
  7133. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7134. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7135. WarehouseOutId: warehouseOut.ID,
  7136. GoodId: item.GoodId,
  7137. Number: warehouseOutInfos.Number,
  7138. ProductDate: stockInInfo.ProductDate,
  7139. ExpireDate: stockInInfo.ExpiryDate,
  7140. Count: exsit.Count - delete_count,
  7141. Price: stockInInfo.Price,
  7142. Status: 1,
  7143. Ctime: record_time,
  7144. UserOrgId: adminInfo.Org.Id,
  7145. Manufacturer: stockInInfo.Manufacturer,
  7146. Dealer: stockInInfo.Dealer,
  7147. LicenseNumber: stockInInfo.LicenseNumber,
  7148. IsEdit: 2,
  7149. Creator: creater,
  7150. SystemTime: record_time,
  7151. ConsumableType: 3,
  7152. WarehousingDetailId: 0,
  7153. IsSys: 1,
  7154. UpdateCreator: creater,
  7155. PatientId: patient_id,
  7156. StorehouseId: houseConfig.StorehouseOutInfo,
  7157. }
  7158. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7159. }
  7160. } else if errcod == nil {
  7161. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7162. //查询剩余库存
  7163. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7164. var sum_count int64
  7165. for _, item := range goodList {
  7166. sum_count += item.StockCount
  7167. }
  7168. //创建退库单,生成退库数据
  7169. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7170. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7171. operation_time := time.Now().Unix()
  7172. creater := adminInfo.AdminUser.Id
  7173. //创建退库单
  7174. timeStr := time.Now().Format("2006-01-02")
  7175. timeArr := strings.Split(timeStr, "-")
  7176. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7177. total = total + 1
  7178. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7179. cancelStock := models.CancelStock{
  7180. OrderNumber: orderNumber,
  7181. OperaTime: operation_time,
  7182. OrgId: adminInfo.Org.Id,
  7183. Creater: creater,
  7184. Ctime: time.Now().Unix(),
  7185. Status: 1,
  7186. ReturnTime: record_time,
  7187. Type: 1,
  7188. StorehouseId: houseConfig.StorehouseOutInfo,
  7189. IsCheck: 1,
  7190. }
  7191. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7192. if msgerrkonde == gorm.ErrRecordNotFound {
  7193. service.AddSigleCancelStock(&cancelStock)
  7194. }
  7195. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7196. //查询是否有出库
  7197. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7198. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7199. deaerler, _ := service.GetDealerById(info.Dealer)
  7200. if info.ID > 0 {
  7201. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7202. cancelStockInfo := models.CancelStockInfo{
  7203. GoodId: item.GoodId,
  7204. CancelStockId: cancel.ID,
  7205. GoodTypeId: good.GoodTypeId,
  7206. Count: delete_count,
  7207. Price: info.Price,
  7208. Total: 0,
  7209. ProductDate: info.ProductDate,
  7210. ExpiryDate: info.ExpiryDate,
  7211. Ctime: time.Now().Unix(),
  7212. Status: 1,
  7213. OrgId: adminInfo.Org.Id,
  7214. OrderNumber: cancel.OrderNumber,
  7215. Type: 0,
  7216. Dealer: deaerler.DealerName,
  7217. Manufacturer: manufacturer.ManufacturerName,
  7218. Number: info.Number,
  7219. RegisterAccount: "",
  7220. Remark: "",
  7221. WarehouseInfoId: info.WarehouseInfotId,
  7222. PatientId: info.PatientId,
  7223. RecordDate: info.SysRecordTime,
  7224. StorehouseId: houseConfig.StorehouseOutInfo,
  7225. IsCheck: 1,
  7226. }
  7227. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7228. //退库数量增加
  7229. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7230. //查询剩余库存
  7231. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7232. var over_count int64
  7233. for _, it := range goodList {
  7234. over_count += it.StockCount
  7235. }
  7236. flow := models.VmStockFlow{
  7237. WarehousingId: info.WarehouseInfotId,
  7238. GoodId: item.GoodId,
  7239. Number: info.Number,
  7240. LicenseNumber: info.LicenseNumber,
  7241. Count: delete_count,
  7242. UserOrgId: adminInfo.Org.Id,
  7243. PatientId: patient_id,
  7244. SystemTime: info.SysRecordTime,
  7245. ConsumableType: 7,
  7246. IsSys: 0,
  7247. WarehousingOrder: "",
  7248. WarehouseOutId: info.WarehouseOutId,
  7249. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7250. IsEdit: 0,
  7251. CancelStockId: cancel.ID,
  7252. CancelOrderNumber: cancel.OrderNumber,
  7253. Manufacturer: manufacturer.ID,
  7254. Dealer: 0,
  7255. Creator: adminInfo.AdminUser.Id,
  7256. UpdateCreator: 0,
  7257. Status: 1,
  7258. Ctime: record_time,
  7259. Mtime: 0,
  7260. Price: info.Price,
  7261. WarehousingDetailId: info.WarehouseInfotId,
  7262. WarehouseOutDetailId: info.ID,
  7263. CancelOutDetailId: cancelInfo.ID,
  7264. ProductDate: info.ProductDate,
  7265. ExpireDate: info.ExpiryDate,
  7266. StorehouseId: houseConfig.StorehouseOutInfo,
  7267. OverCount: over_count,
  7268. }
  7269. service.CreateStockFlowOne(flow)
  7270. }
  7271. }
  7272. //更改自动出库的表格
  7273. details := models.BloodAutomaticReduceDetail{
  7274. WarehouseOutId: warehouseOutInfo.ID,
  7275. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7276. PatientId: patient_id,
  7277. Ctime: time.Now().Unix(),
  7278. Mtime: time.Now().Unix(),
  7279. Status: 1,
  7280. RecordTime: record_time,
  7281. OrgId: adminInfo.Org.Id,
  7282. GoodId: item.GoodId,
  7283. GoodTypeId: item.GoodTypeId,
  7284. Count: item.Count,
  7285. StorehouseId: houseConfig.StorehouseOutInfo,
  7286. }
  7287. //查询当天耗材是否已经存在数据
  7288. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7289. if errcode == gorm.ErrRecordNotFound {
  7290. service.CreateAutoReduceRecord(&details)
  7291. } else if errcode == nil {
  7292. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7293. service.CreateAutoReduceRecord(&details)
  7294. }
  7295. //查询默认仓库
  7296. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7297. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7298. var total_count int64
  7299. for _, it := range stockList {
  7300. total_count += it.StockCount
  7301. }
  7302. //基础库插入数据
  7303. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7304. }
  7305. }
  7306. if len(outbefor) > 0 {
  7307. //出库
  7308. for _, item := range outbefor {
  7309. var last_total int64
  7310. //1.查看该患者该耗材型号最后一次出库数量
  7311. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7312. //计算当前出库和最后一次出库数据相差数据
  7313. last_total = item.Count - goodInfoOne.Count
  7314. //查询该耗材的总库存
  7315. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7316. // 如果库存差大于剩余库存则提示库存不足
  7317. if last_total > wareinfo.StockCount {
  7318. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7319. c.ServeSuccessJSON(map[string]interface{}{
  7320. "message": "1",
  7321. "good_name": goodObj.GoodName,
  7322. "specification_name": goodObj.SpecificationName,
  7323. })
  7324. return
  7325. } else {
  7326. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7327. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7328. if err == gorm.ErrRecordNotFound {
  7329. //没有记录,则创建出库单
  7330. timeStr := time.Now().Format("2006-01-02")
  7331. timeArr := strings.Split(timeStr, "-")
  7332. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7333. total = total + 1
  7334. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7335. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7336. number = number + total
  7337. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7338. warehouseOut := models.WarehouseOut{
  7339. WarehouseOutOrderNumber: warehousing_out_order,
  7340. OperationTime: time.Now().Unix(),
  7341. OrgId: adminInfo.Org.Id,
  7342. Creater: adminInfo.AdminUser.Id,
  7343. Ctime: time.Now().Unix(),
  7344. Status: 1,
  7345. WarehouseOutTime: record_time,
  7346. Dealer: 0,
  7347. Manufacturer: 0,
  7348. Type: 1,
  7349. IsSys: 1,
  7350. StorehouseId: houseConfig.StorehouseOutInfo,
  7351. IsCheck: 1,
  7352. }
  7353. service.AddSigleWarehouseOut(&warehouseOut)
  7354. }
  7355. //出库
  7356. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7357. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7358. //1.查看该患者该耗材型号最后一次出库数量
  7359. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7360. prepare := models.DialysisBeforePrepare{
  7361. UserOrgId: adminInfo.Org.Id,
  7362. PatientId: patient_id,
  7363. RecordDate: record_time,
  7364. GoodId: item.GoodId,
  7365. GoodTypeId: item.GoodTypeId,
  7366. Count: item.Count - goodInfoTwo.Count,
  7367. Ctime: time.Now().Unix(),
  7368. Mtime: 0,
  7369. Creater: adminInfo.AdminUser.Id,
  7370. Modifier: adminInfo.AdminUser.Id,
  7371. Status: 1,
  7372. CommdityCode: "",
  7373. NewCount: 0,
  7374. ProjectId: 0,
  7375. StorehouseId: houseConfig.StorehouseOutInfo,
  7376. }
  7377. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7378. //增加出库数量
  7379. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7380. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7381. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7382. var total_count int64
  7383. for _, it := range stockList {
  7384. total_count += it.StockCount
  7385. }
  7386. //基础库插入数据
  7387. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7388. //剩余库存
  7389. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7390. var flush_count int64
  7391. for _, it := range goodList {
  7392. flush_count += it.StockCount
  7393. }
  7394. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7395. }
  7396. }
  7397. }
  7398. //查询今日出库数据
  7399. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7400. for _, it := range list {
  7401. prepare := models.DialysisBeforePrepare{
  7402. UserOrgId: it.OrgId,
  7403. PatientId: patient_id,
  7404. RecordDate: it.RecordTime,
  7405. GoodId: it.GoodId,
  7406. GoodTypeId: it.GoodTypeId,
  7407. Count: it.Count,
  7408. Ctime: time.Now().Unix(),
  7409. Creater: adminInfo.AdminUser.Id,
  7410. Status: 1,
  7411. StorehouseId: houseConfig.StorehouseOutInfo,
  7412. ProjectId: it.ProjectId,
  7413. }
  7414. //删除准备表数据
  7415. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7416. service.CreateDialysisBeforePrepareOne(&prepare)
  7417. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7418. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7419. var total_count int64
  7420. for _, it := range stockList {
  7421. total_count += it.StockCount
  7422. }
  7423. //基础库插入数据
  7424. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7425. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7426. var flush_count int64
  7427. for _, it := range goodList {
  7428. flush_count += it.StockCount
  7429. }
  7430. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7431. }
  7432. }
  7433. }
  7434. //更新自动出库的地方
  7435. var errs error
  7436. if errs == nil {
  7437. c.ServeSuccessJSON(map[string]interface{}{
  7438. "msg": "修改成功",
  7439. "message": "2",
  7440. "good_name": "",
  7441. "specification_name": "",
  7442. })
  7443. return
  7444. } else {
  7445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7446. return
  7447. }
  7448. }
  7449. }
  7450. func (c *DialysisAPIController) GetDialysisGoods() {
  7451. schedualDate := c.GetString("schedule_date")
  7452. schedule_type, _ := c.GetInt64("schedule_type")
  7453. partition_id, _ := c.GetInt64("partition_id")
  7454. page, _ := c.GetInt("page")
  7455. patient_id, _ := c.GetInt64("patient_id")
  7456. schedualEndDate := int64(0)
  7457. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7458. if parseDateErr != nil && len(schedualDate) != 0 {
  7459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7460. return
  7461. }
  7462. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7463. if parseDateErr != nil && len(schedualDate) != 0 {
  7464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7465. return
  7466. }
  7467. schedualEndDate = endDate.Unix()
  7468. adminUser := c.GetMobileAdminUserInfo()
  7469. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7470. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7471. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7472. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7473. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7474. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7475. //获取当天该病人的透析处方
  7476. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7477. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7478. if err == gorm.ErrRecordNotFound {
  7479. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7480. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7481. if patient_id != 0 {
  7482. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7483. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7484. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7485. //获取患者总的出库数据
  7486. item.LastAutomaticReduceDetail = goodUser
  7487. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7488. item.Project = project
  7489. for _, it := range item.AutomaticReduceDetail {
  7490. var total int64
  7491. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7492. for _, its := range auto {
  7493. total += its.Count
  7494. }
  7495. it.Count = total
  7496. }
  7497. }
  7498. }
  7499. c.ServeSuccessJSON(map[string]interface{}{
  7500. "dialysis_goods": dialysisGoods,
  7501. "good_type": goodTypes,
  7502. "total": total,
  7503. "prescribe": prescribe,
  7504. "good_info": good_info,
  7505. "warehouseOutList": warehouseOutList,
  7506. "config": config,
  7507. "outConfig": outConfig,
  7508. "settleConfig": settleConfig,
  7509. })
  7510. return
  7511. } else if err == nil {
  7512. //获取当天排班的每个患者的库存使用情况
  7513. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7514. //获取患者总的出库数据
  7515. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7516. if patient_id != 0 {
  7517. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7518. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7519. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7520. item.Project = project
  7521. item.LastAutomaticReduceDetail = goodUser
  7522. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7523. for _, it := range item.AutomaticReduceDetail {
  7524. var total int64
  7525. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7526. for _, its := range auto {
  7527. total += its.Count
  7528. }
  7529. it.Count = total
  7530. }
  7531. }
  7532. }
  7533. if err == nil {
  7534. c.ServeSuccessJSON(map[string]interface{}{
  7535. "dialysis_goods": dialysisGoods,
  7536. "good_type": goodTypes,
  7537. "total": total,
  7538. "prescribe": prescribe,
  7539. "good_info": good_info,
  7540. "project": project,
  7541. "warehouseOutList": warehouseOutList,
  7542. "config": config,
  7543. "outConfig": outConfig,
  7544. "settleConfig": settleConfig,
  7545. })
  7546. return
  7547. } else {
  7548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7549. return
  7550. }
  7551. } else if err != nil {
  7552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7553. return
  7554. }
  7555. }
  7556. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7557. start_time := c.GetString("start_time")
  7558. end_time := c.GetString("end_time")
  7559. timeLayout := "2006-01-02"
  7560. loc, _ := time.LoadLocation("Local")
  7561. var theStartTime int64
  7562. if len(start_time) > 0 {
  7563. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7564. if err != nil {
  7565. utils.ErrorLog(err.Error())
  7566. }
  7567. theStartTime = theTime.Unix()
  7568. }
  7569. var theEndtTime int64
  7570. if len(end_time) > 0 {
  7571. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7572. if err != nil {
  7573. utils.ErrorLog(err.Error())
  7574. }
  7575. theEndtTime = theTime.Unix()
  7576. }
  7577. adminUser := c.GetMobileAdminUserInfo()
  7578. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7579. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7580. if err == nil {
  7581. c.ServeSuccessJSON(map[string]interface{}{
  7582. "stock_out": outInfo,
  7583. "stockCount": stockCount,
  7584. })
  7585. return
  7586. } else {
  7587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7588. return
  7589. }
  7590. }
  7591. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7592. patient_id, _ := c.GetInt64("patient_id", 0)
  7593. record_time := c.GetString("record_time")
  7594. adminUser := c.GetMobileAdminUserInfo()
  7595. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7596. if parseDateErr != nil && len(record_time) != 0 {
  7597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7598. return
  7599. }
  7600. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7601. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7602. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7603. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7604. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7605. //获取今日患者的透析处方参数
  7606. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7607. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7608. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7609. c.ServeSuccessJSON(map[string]interface{}{
  7610. "good_type": goodTypes,
  7611. "good_user": goodUser,
  7612. "good_info": good_info,
  7613. "last_good_user": lastGoodUserDetial,
  7614. "project": project,
  7615. "prescription": prescribe,
  7616. "outInfo": outInfo,
  7617. "configs": configs,
  7618. })
  7619. return
  7620. }
  7621. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7622. patient_id, _ := c.GetInt64("patient_id", 0)
  7623. record_date := c.GetString("record_time")
  7624. timeLayout := "2006-01-02"
  7625. loc, _ := time.LoadLocation("Local")
  7626. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7627. record_time := theRecordTime.Unix()
  7628. adminInfo := c.GetMobileAdminUserInfo()
  7629. dataBody := make(map[string]interface{}, 0)
  7630. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7631. if err != nil {
  7632. utils.ErrorLog(err.Error())
  7633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7634. return
  7635. }
  7636. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7637. var beforePrepares []*models.DialysisBeforePrepareGoods
  7638. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7639. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7640. goods, _ := dataBody["goods"].([]interface{})
  7641. if len(goods) > 0 {
  7642. for _, item := range goods {
  7643. items := item.(map[string]interface{})
  7644. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7645. utils.ErrorLog("good_id")
  7646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7647. return
  7648. }
  7649. good_id := int64(items["good_id"].(float64))
  7650. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7651. utils.ErrorLog("good_type_id")
  7652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7653. return
  7654. }
  7655. good_type_id := int64(items["good_type_id"].(float64))
  7656. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7657. utils.ErrorLog("count")
  7658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7659. return
  7660. }
  7661. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7662. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7663. utils.ErrorLog("project_id")
  7664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7665. return
  7666. }
  7667. project_id := int64(items["project_id"].(float64))
  7668. new_count := int64(items["new_count"].(float64))
  7669. old_count := int64(items["old_count"].(float64))
  7670. prepare := &models.DialysisBeforePrepareGoods{
  7671. GoodId: good_id,
  7672. GoodTypeId: good_type_id,
  7673. Count: count,
  7674. ProjectId: project_id,
  7675. StorehouseId: houseConfig.StorehouseOutInfo,
  7676. NewCount: new_count,
  7677. OldCount: old_count,
  7678. }
  7679. beforePrepares = append(beforePrepares, prepare)
  7680. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7681. GoodId: good_id,
  7682. GoodTypeId: good_type_id,
  7683. Count: count,
  7684. ProjectId: project_id,
  7685. StorehouseId: houseConfig.StorehouseOutInfo,
  7686. NewCount: new_count,
  7687. OldCount: old_count,
  7688. }
  7689. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7690. }
  7691. }
  7692. }
  7693. //查询是否有库存
  7694. for _, item := range beforePrepares {
  7695. if item.NewCount > 0 {
  7696. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7697. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7698. if item.Count > warehouse.Count {
  7699. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7700. c.ServeSuccessJSON(map[string]interface{}{
  7701. "message": "1",
  7702. "good_name": goodObj.GoodName,
  7703. "specification_name": goodObj.SpecificationName,
  7704. })
  7705. return
  7706. }
  7707. }
  7708. }
  7709. // 查询信息规挡的设置天数
  7710. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7711. if infor.ID > 0 && infor.WeekDay > 0 {
  7712. var cha_time int64
  7713. timeNowStr := time.Now().Format("2006-01-02")
  7714. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7715. //今日的日期减去设置的日期
  7716. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7717. if cha_time >= record_time {
  7718. //查询审核是否允许
  7719. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7720. //申请状态不允许的情况 拒绝修改
  7721. if infor.ApplicationStatus != 1 {
  7722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7723. return
  7724. }
  7725. }
  7726. }
  7727. //出库逻辑
  7728. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7729. if err != nil {
  7730. utils.ErrorLog(err.Error())
  7731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7732. return
  7733. }
  7734. finish := models.XtDialysisFinish{
  7735. IsFinish: 1,
  7736. UserOrgId: adminInfo.Org.Id,
  7737. Status: 1,
  7738. Ctime: time.Now().Unix(),
  7739. Mtime: 0,
  7740. Module: 11,
  7741. RecordDate: record_time,
  7742. Sourse: 1,
  7743. PatientId: patient_id,
  7744. }
  7745. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7746. if dialysisFinish.ID == 0 {
  7747. service.CreateDialysisFinish(finish)
  7748. }
  7749. //查询当天出库的数据
  7750. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7751. for _, item := range list {
  7752. prepare := models.DialysisBeforePrepare{
  7753. UserOrgId: item.OrgId,
  7754. PatientId: item.PatientId,
  7755. RecordDate: item.RecordTime,
  7756. GoodId: item.GoodId,
  7757. GoodTypeId: item.GoodTypeId,
  7758. Count: item.Count,
  7759. Creater: adminInfo.AdminUser.Id,
  7760. Status: 1,
  7761. Ctime: time.Now().Unix(),
  7762. ProjectId: item.ProjectId,
  7763. StorehouseId: houseConfig.StorehouseOutInfo,
  7764. }
  7765. //清空准备表的数据
  7766. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7767. //插入准备表数据
  7768. service.CreateDialysisBeforePrepareOne(&prepare)
  7769. //查询默认仓库
  7770. //查询默认仓库
  7771. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7772. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7773. var total_count int64
  7774. for _, it := range stockList {
  7775. total_count += it.StockCount
  7776. }
  7777. //基础库插入数据
  7778. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7779. ////更新剩余库存
  7780. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7781. var flush_count int64
  7782. for _, it := range goodList {
  7783. flush_count += it.StockCount
  7784. }
  7785. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7786. if errs != nil {
  7787. goodErrcode := models.XtGoodErrcode{
  7788. UserOrgId: item.OrgId,
  7789. Errcode: "手动出库更新剩余出库失败",
  7790. GoodId: item.GoodId,
  7791. Status: 1,
  7792. Ctime: time.Now().Unix(),
  7793. Mtime: 0,
  7794. Count: 0,
  7795. StockCount: 0,
  7796. Creater: adminInfo.AdminUser.Id,
  7797. BatchNumberId: 0,
  7798. WarehouseOutId: 0,
  7799. }
  7800. service.CreateGoodErrcode(goodErrcode)
  7801. }
  7802. }
  7803. //更新自动出库的地方
  7804. var errs error
  7805. if errs == nil {
  7806. c.ServeSuccessJSON(map[string]interface{}{
  7807. "msg": "修改成功",
  7808. "message": "2",
  7809. "good_name": "",
  7810. "specification_name": "",
  7811. })
  7812. return
  7813. } else {
  7814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7815. return
  7816. }
  7817. }
  7818. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7819. newArr = make([]*models.DialysisBeforePrepare, 0)
  7820. for i := 0; i < len(arr); i++ {
  7821. repeat := false
  7822. for j := i + 1; j < len(arr); j++ {
  7823. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7824. repeat = true
  7825. break
  7826. }
  7827. }
  7828. if !repeat {
  7829. newArr = append(newArr, arr[i])
  7830. }
  7831. }
  7832. return
  7833. }
  7834. func (c *DialysisAPIController) GetAllDrug() {
  7835. patient_id, _ := c.GetInt64("patient_id", 0)
  7836. adminInfo := c.GetMobileAdminUserInfo()
  7837. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7838. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7839. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7840. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7841. c.ServeSuccessJSON(map[string]interface{}{
  7842. "base_drug_config": drugStockConfig,
  7843. "private_drug_config": privateDrugConfig,
  7844. "base_drug_list": drugList,
  7845. "private_drug_list": privateDrugList,
  7846. })
  7847. }
  7848. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7849. newArr = make([]*models.DialysisBeforePrepare, 0)
  7850. for i := 0; i < len(arr); i++ {
  7851. repeat := false
  7852. for j := i + 1; j < len(arr); j++ {
  7853. if arr[i].GoodId == arr[j].GoodId {
  7854. repeat = true
  7855. break
  7856. }
  7857. }
  7858. if !repeat {
  7859. newArr = append(newArr, arr[i])
  7860. }
  7861. }
  7862. return
  7863. }
  7864. func (c *DialysisAPIController) GetDepartment() {
  7865. adminInfo := c.GetMobileAdminUserInfo()
  7866. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7867. if err == nil {
  7868. c.ServeSuccessJSON(map[string]interface{}{
  7869. "departments": departments,
  7870. })
  7871. } else {
  7872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7873. return
  7874. }
  7875. }
  7876. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7877. types, _ := c.GetInt("type", 0)
  7878. start_time := c.GetString("start_time")
  7879. end_time := c.GetString("end_time")
  7880. orgId := c.GetMobileAdminUserInfo().Org.Id
  7881. timeLayout := "2006-01-02"
  7882. loc, _ := time.LoadLocation("Local")
  7883. var startTime int64
  7884. if len(start_time) > 0 {
  7885. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7886. if err != nil {
  7887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7888. return
  7889. }
  7890. startTime = theTime.Unix()
  7891. }
  7892. var endTime int64
  7893. if len(end_time) > 0 {
  7894. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7895. if err != nil {
  7896. utils.ErrorLog(err.Error())
  7897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7898. return
  7899. }
  7900. endTime = theTime.Unix()
  7901. }
  7902. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7903. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7904. if err != nil {
  7905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7906. } else {
  7907. c.ServeSuccessJSON(map[string]interface{}{
  7908. "list": list,
  7909. "type": types,
  7910. "stockTotal": stockTotal,
  7911. })
  7912. }
  7913. }
  7914. func (c *DialysisAPIController) GetPrescriptionList() {
  7915. start_time := c.GetString("start_time")
  7916. end_time := c.GetString("end_time")
  7917. schedule_type, _ := c.GetInt64("schedule_type")
  7918. partion_id, _ := c.GetInt64("partion_id")
  7919. orgId := c.GetMobileAdminUserInfo().Org.Id
  7920. timeLayout := "2006-01-02"
  7921. loc, _ := time.LoadLocation("Local")
  7922. var startTime int64
  7923. if len(start_time) > 0 {
  7924. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7925. if err != nil {
  7926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7927. return
  7928. }
  7929. startTime = theTime.Unix()
  7930. }
  7931. var endTime int64
  7932. if len(end_time) > 0 {
  7933. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7934. if err != nil {
  7935. utils.ErrorLog(err.Error())
  7936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7937. return
  7938. }
  7939. endTime = theTime.Unix()
  7940. }
  7941. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7942. fmt.Println("schedulelist22222222", schedulelist)
  7943. c.ServeSuccessJSON(map[string]interface{}{
  7944. "list": schedulelist,
  7945. })
  7946. return
  7947. }
  7948. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7949. ids := c.GetString("ids")
  7950. //patient_id, _ := c.GetInt64("patient_id")
  7951. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7952. idArray := strings.Split(ids, ",")
  7953. err := service.BatchDeleteMonitor(idArray)
  7954. fmt.Print("err", err)
  7955. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7956. //redis := service.RedisClient()
  7957. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7958. //redis.Set(key, "", time.Second)
  7959. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7960. //redis.Set(keyOne, "", time.Second)
  7961. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7962. //redis.Close()
  7963. c.ServeSuccessJSON(map[string]interface{}{
  7964. "msg": "批量删除成功",
  7965. })
  7966. return
  7967. }
  7968. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7969. id, _ := c.GetInt64("id")
  7970. timeLayout := "2006-01-02"
  7971. loc, _ := time.LoadLocation("Local")
  7972. //start_time := time.Now().Format("2006-01-02")
  7973. start_time := c.GetString("start_time")
  7974. end_time := c.GetString("end_time")
  7975. var startdateunix int64
  7976. if len(start_time) > 0 {
  7977. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7978. if err != nil {
  7979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7980. return
  7981. }
  7982. startdateunix = theTime.Unix()
  7983. }
  7984. var enddateunix int64
  7985. if len(end_time) > 0 {
  7986. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7987. if err != nil {
  7988. utils.ErrorLog(err.Error())
  7989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7990. return
  7991. }
  7992. enddateunix = theTime.Unix()
  7993. }
  7994. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7995. //nowTime := time.Now()
  7996. //endTime := nowTime.AddDate(-30, 0, 0)
  7997. //endTimes := endTime.Format("2006-01-02")
  7998. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7999. org_id := c.GetMobileAdminUserInfo().Org.Id
  8000. //if org_id == 10579 {
  8001. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8002. // c.ServeSuccessJSON(map[string]interface{}{
  8003. // "list": list,
  8004. // })
  8005. // return
  8006. //} else {
  8007. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8008. // c.ServeSuccessJSON(map[string]interface{}{
  8009. // "list": list,
  8010. // })
  8011. // return
  8012. //}
  8013. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8014. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8015. c.ServeSuccessJSON(map[string]interface{}{
  8016. "list": list,
  8017. })
  8018. return
  8019. } else {
  8020. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8021. c.ServeSuccessJSON(map[string]interface{}{
  8022. "list": list,
  8023. })
  8024. }
  8025. return
  8026. }
  8027. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8028. dataBody := make(map[string]interface{}, 0)
  8029. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8030. ids := c.GetString("ids")
  8031. idArray := strings.Split(ids, ",")
  8032. origin, _ := c.GetInt64("origin")
  8033. if origin == 1 {
  8034. err = service.BatchDeleteAdvice(idArray)
  8035. fmt.Print("err", err)
  8036. c.ServeSuccessJSON(map[string]interface{}{
  8037. "msg": "批量删除成功",
  8038. })
  8039. return
  8040. }
  8041. if origin == 2 {
  8042. service.BatchDeleteHisAdvice(idArray)
  8043. }
  8044. }
  8045. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8046. good_id, _ := c.GetInt64("good_id")
  8047. count, _ := c.GetInt64("count")
  8048. record_time, _ := c.GetInt64("record_time")
  8049. patient_id, _ := c.GetInt64("patient_id")
  8050. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8051. c.ServeSuccessJSON(map[string]interface{}{
  8052. "detail": detail,
  8053. })
  8054. return
  8055. }
  8056. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8057. good_id, _ := c.GetInt64("good_id")
  8058. record_time, _ := c.GetInt64("record_time")
  8059. patient_id, _ := c.GetInt64("patient_id")
  8060. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8061. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8062. fmt.Print("err", err)
  8063. c.ServeSuccessJSON(map[string]interface{}{
  8064. "msg": "批量删除成功",
  8065. })
  8066. return
  8067. }
  8068. func (c *DialysisAPIController) BatchAdviceCheck() {
  8069. ids := c.GetString("ids")
  8070. idArray := strings.Split(ids, ",")
  8071. creator, _ := c.GetInt64("creator")
  8072. origin, _ := c.GetInt64("origin")
  8073. if origin == 1 {
  8074. err := service.BatchAdviceCheck(idArray, creator)
  8075. fmt.Println(err)
  8076. list, _ := service.GetAdviceExecutionById(idArray)
  8077. c.ServeSuccessJSON(map[string]interface{}{
  8078. "list": list,
  8079. })
  8080. return
  8081. }
  8082. if origin == 2 {
  8083. service.BatchHisAdviceCheck(idArray, creator)
  8084. list, _ := service.GetHisAdviceExecutionById(idArray)
  8085. c.ServeSuccessJSON(map[string]interface{}{
  8086. "list": list,
  8087. })
  8088. return
  8089. }
  8090. }
  8091. func (c *DialysisAPIController) BatchAdviceExecution() {
  8092. ids := c.GetString("ids")
  8093. idArray := strings.Split(ids, ",")
  8094. executionTime := c.GetString("execution_time")
  8095. creator, _ := c.GetInt64("creator")
  8096. timeLayout := "2006-01-02 15:04:05"
  8097. loc, _ := time.LoadLocation("Local")
  8098. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8099. orgin, _ := c.GetInt64("origin")
  8100. if orgin == 1 {
  8101. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8102. list, _ := service.GetAdviceExecutionById(idArray)
  8103. fmt.Println(err)
  8104. c.ServeSuccessJSON(map[string]interface{}{
  8105. "list": list,
  8106. })
  8107. return
  8108. }
  8109. if orgin == 2 {
  8110. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8111. list, _ := service.GetHisAdviceExecutionById(idArray)
  8112. fmt.Println(err)
  8113. c.ServeSuccessJSON(map[string]interface{}{
  8114. "list": list,
  8115. })
  8116. return
  8117. }
  8118. }
  8119. func (c *DialysisAPIController) UpdateStockGoods() {
  8120. good_id, _ := c.GetInt64("good_id")
  8121. record_time, _ := c.GetInt64("record_time")
  8122. patient_id, _ := c.GetInt64("patient_id")
  8123. count, _ := c.GetInt64("count")
  8124. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8125. fmt.Print("err", err)
  8126. c.ServeSuccessJSON(map[string]interface{}{
  8127. "msg": "更新成功",
  8128. })
  8129. return
  8130. }
  8131. // 当前数据比上一次出库数据少
  8132. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8133. //查询该患者当天已经出库的耗材信息
  8134. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8135. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8136. for i := len(goods_yc) - 1; i >= 0; i-- {
  8137. goods_yc_temp := goods_yc[i]
  8138. for j := len(goods) - 1; j >= 0; j-- {
  8139. goods_temp := goods[j]
  8140. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8141. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8142. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8143. if goods_yc_temp.Count == goods_temp.Count {
  8144. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8145. goods = append(goods[:j], goods[j+1:]...)
  8146. break
  8147. }
  8148. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8149. if goods_yc_temp.Count > goods_temp.Count {
  8150. temp_count := goods_yc_temp.Count - goods_temp.Count
  8151. goods_yc[i].Count = temp_count
  8152. goods = append(goods[:j], goods[j+1:]...)
  8153. break
  8154. }
  8155. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8156. if goods_yc_temp.Count < goods_temp.Count {
  8157. temp_count := goods_temp.Count - goods_yc_temp.Count
  8158. goods[j].Count = temp_count
  8159. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8160. break
  8161. }
  8162. }
  8163. }
  8164. }
  8165. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8166. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8167. //退库
  8168. if len(goods_yc) > 0 {
  8169. for _, good_yc := range goods_yc {
  8170. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8171. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8172. }
  8173. }
  8174. return nil
  8175. }
  8176. // 耗材出库删除
  8177. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8178. // 先根据相关信息查询当天该耗材的出库信息
  8179. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8180. if err != nil {
  8181. return err
  8182. }
  8183. var delete_count int64 = 0
  8184. delete_count = warehouseOutInfos.Count - count
  8185. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8186. // 在出库记录表里记录退库详情
  8187. warehouseOutInfo := &models.WarehouseOutInfo{
  8188. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8189. WarehouseOutId: warehouseOut.ID,
  8190. Status: 1,
  8191. Ctime: time.Now().Unix(),
  8192. OrgId: orgID,
  8193. Type: 1,
  8194. IsSys: 1,
  8195. SysRecordTime: record_time,
  8196. GoodTypeId: good_yc.GoodTypeId,
  8197. GoodId: good_yc.GoodId,
  8198. PatientId: good_yc.PatientId,
  8199. ConsumableType: 2,
  8200. StorehouseId: houseConfig.StorehouseOutInfo,
  8201. IsCheck: 1,
  8202. }
  8203. warehouseOutInfo.Count = count
  8204. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8205. warehouseOutInfo.Price = stockInInfo.Price
  8206. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8207. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8208. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8209. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8210. warehouseOutInfo.Number = warehouseOutInfos.Number
  8211. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8212. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8213. //查找当天是否存在出库记录
  8214. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8215. if errcod == gorm.ErrRecordNotFound {
  8216. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8217. //插入详情明细表
  8218. stockFlow := models.VmStockFlow{
  8219. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8220. WarehouseOutId: warehouseOut.ID,
  8221. GoodId: good_yc.GoodId,
  8222. Number: warehouseOutInfos.Number,
  8223. ProductDate: stockInInfo.ProductDate,
  8224. ExpireDate: stockInInfo.ExpiryDate,
  8225. Count: count,
  8226. Price: stockInInfo.Price,
  8227. Status: 1,
  8228. Ctime: time.Now().Unix(),
  8229. UserOrgId: good_yc.OrgId,
  8230. Manufacturer: stockInInfo.Manufacturer,
  8231. Dealer: stockInInfo.Dealer,
  8232. LicenseNumber: stockInInfo.LicenseNumber,
  8233. IsEdit: 2,
  8234. Creator: creater,
  8235. SystemTime: record_time,
  8236. ConsumableType: 3,
  8237. WarehousingDetailId: 0,
  8238. IsSys: 1,
  8239. UpdateCreator: creater,
  8240. PatientId: patient_id,
  8241. StorehouseId: houseConfig.StorehouseOutInfo,
  8242. }
  8243. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8244. if errflow == gorm.ErrRecordNotFound {
  8245. //创建流水表
  8246. err := service.CreateStockFlowOne(stockFlow)
  8247. fmt.Println("err", err)
  8248. } else if errflow == nil {
  8249. //插入详情明细表
  8250. stockFlow := models.VmStockFlow{
  8251. ID: exsit.ID,
  8252. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8253. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8254. WarehouseOutId: warehouseOut.ID,
  8255. GoodId: good_yc.GoodId,
  8256. Number: warehouseOutInfos.Number,
  8257. ProductDate: stockInInfo.ProductDate,
  8258. ExpireDate: stockInInfo.ExpiryDate,
  8259. Count: exsit.Count - delete_count,
  8260. Price: stockInInfo.Price,
  8261. Status: 1,
  8262. Ctime: time.Now().Unix(),
  8263. UserOrgId: good_yc.OrgId,
  8264. Manufacturer: stockInInfo.Manufacturer,
  8265. Dealer: stockInInfo.Dealer,
  8266. LicenseNumber: stockInInfo.LicenseNumber,
  8267. IsEdit: 2,
  8268. Creator: creater,
  8269. SystemTime: record_time,
  8270. ConsumableType: 3,
  8271. WarehousingDetailId: 0,
  8272. IsSys: 1,
  8273. UpdateCreator: creater,
  8274. PatientId: patient_id,
  8275. StorehouseId: houseConfig.StorehouseOutInfo,
  8276. }
  8277. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8278. }
  8279. if errOne != nil {
  8280. return errOne
  8281. }
  8282. } else if errcod == nil {
  8283. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8284. //插入详情明细表
  8285. stockFlow := models.VmStockFlow{
  8286. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8287. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8288. WarehouseOutId: warehouseOut.ID,
  8289. GoodId: good_yc.GoodId,
  8290. Number: warehouseOutInfos.Number,
  8291. ProductDate: stockInInfo.ProductDate,
  8292. ExpireDate: stockInInfo.ExpiryDate,
  8293. Count: count,
  8294. Price: stockInInfo.Price,
  8295. Status: 1,
  8296. Ctime: time.Now().Unix(),
  8297. UserOrgId: good_yc.OrgId,
  8298. Manufacturer: stockInInfo.Manufacturer,
  8299. Dealer: stockInInfo.Dealer,
  8300. LicenseNumber: stockInInfo.LicenseNumber,
  8301. IsEdit: 2,
  8302. Creator: creater,
  8303. SystemTime: record_time,
  8304. ConsumableType: 3,
  8305. WarehousingDetailId: 0,
  8306. IsSys: 1,
  8307. UpdateCreator: creater,
  8308. PatientId: patient_id,
  8309. ReturnCount: delete_count,
  8310. StorehouseId: houseConfig.StorehouseOutInfo,
  8311. }
  8312. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8313. if errflows == gorm.ErrRecordNotFound {
  8314. //创建流水表
  8315. service.CreateStockFlowOne(stockFlow)
  8316. } else if errflows == nil {
  8317. stockFlow := models.VmStockFlow{
  8318. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8319. ID: exsit.ID,
  8320. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8321. WarehouseOutId: warehouseOut.ID,
  8322. GoodId: good_yc.GoodId,
  8323. Number: warehouseOutInfos.Number,
  8324. ProductDate: stockInInfo.ProductDate,
  8325. ExpireDate: stockInInfo.ExpiryDate,
  8326. Count: exsit.Count - delete_count,
  8327. Price: stockInInfo.Price,
  8328. Status: 1,
  8329. Ctime: time.Now().Unix(),
  8330. UserOrgId: good_yc.OrgId,
  8331. Manufacturer: stockInInfo.Manufacturer,
  8332. Dealer: stockInInfo.Dealer,
  8333. LicenseNumber: stockInInfo.LicenseNumber,
  8334. IsEdit: 2,
  8335. Creator: creater,
  8336. SystemTime: record_time,
  8337. ConsumableType: 3,
  8338. WarehousingDetailId: 0,
  8339. IsSys: 1,
  8340. UpdateCreator: creater,
  8341. PatientId: patient_id,
  8342. ReturnCount: delete_count,
  8343. StorehouseId: houseConfig.StorehouseOutInfo,
  8344. }
  8345. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8346. }
  8347. }
  8348. //更改自动出库的表格
  8349. details := models.BloodAutomaticReduceDetail{
  8350. WarehouseOutId: warehouseOutInfo.ID,
  8351. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8352. PatientId: patient_id,
  8353. Ctime: time.Now().Unix(),
  8354. Mtime: time.Now().Unix(),
  8355. Status: 1,
  8356. RecordTime: record_time,
  8357. OrgId: orgID,
  8358. GoodId: good_yc.GoodId,
  8359. GoodTypeId: good_yc.GoodTypeId,
  8360. Count: count,
  8361. StorehouseId: houseConfig.StorehouseOutInfo,
  8362. }
  8363. //查询当天耗材是否已经存在数据
  8364. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8365. if errcode == gorm.ErrRecordNotFound {
  8366. errTwo := service.CreateAutoReduceRecord(&details)
  8367. if errTwo != nil {
  8368. return errTwo
  8369. }
  8370. } else if errcode == nil {
  8371. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8372. service.CreateAutoReduceRecord(&details)
  8373. }
  8374. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8375. //增加出库库存数量
  8376. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8377. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8378. fmt.Println("errOne", errOne)
  8379. // 删除出库完成后,要增加对应批次的库存数量
  8380. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8381. if errThree != nil {
  8382. return errThree
  8383. }
  8384. if good_yc.Count == 0 {
  8385. return nil
  8386. } else {
  8387. return errors.New("退库和出库数据不匹配")
  8388. }
  8389. }
  8390. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8391. //查询该患者当天已经出库的耗材信息
  8392. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8393. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8394. for i := len(goods_yc) - 1; i >= 0; i-- {
  8395. goods_yc_temp := goods_yc[i]
  8396. for j := len(goods) - 1; j >= 0; j-- {
  8397. goods_temp := goods[j]
  8398. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8399. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8400. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8401. if goods_yc_temp.Count == goods_temp.Count {
  8402. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8403. goods = append(goods[:j], goods[j+1:]...)
  8404. break
  8405. }
  8406. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8407. if goods_yc_temp.Count > goods_temp.Count {
  8408. temp_count := goods_yc_temp.Count - goods_temp.Count
  8409. goods_yc[i].Count = temp_count
  8410. goods = append(goods[:j], goods[j+1:]...)
  8411. break
  8412. }
  8413. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8414. if goods_yc_temp.Count < goods_temp.Count {
  8415. temp_count := goods_temp.Count - goods_yc_temp.Count
  8416. goods[j].Count = temp_count
  8417. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8418. break
  8419. }
  8420. }
  8421. }
  8422. }
  8423. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8424. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8425. fmt.Println("剩余需要出库的", len(goods))
  8426. if len(goods) > 0 {
  8427. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8428. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8429. if err == gorm.ErrRecordNotFound {
  8430. //没有记录,则创建出库单
  8431. timeStr := time.Now().Format("2006-01-02")
  8432. timeArr := strings.Split(timeStr, "-")
  8433. total, _ := service.FindAllWarehouseOut(orgID)
  8434. total = total + 1
  8435. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8436. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8437. number = number + total
  8438. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8439. warehouseOut := models.WarehouseOut{
  8440. WarehouseOutOrderNumber: warehousing_out_order,
  8441. OperationTime: time.Now().Unix(),
  8442. OrgId: orgID,
  8443. Creater: creater,
  8444. Ctime: time.Now().Unix(),
  8445. Status: 1,
  8446. WarehouseOutTime: record_time,
  8447. Dealer: 0,
  8448. Manufacturer: 0,
  8449. Type: 1,
  8450. IsSys: 1,
  8451. StorehouseId: houseConfig.StorehouseOutInfo,
  8452. IsCheck: 1,
  8453. }
  8454. err := service.AddSigleWarehouseOut(&warehouseOut)
  8455. if err != nil {
  8456. utils.TraceLog("创建出库单失败 err = %v", err)
  8457. return err
  8458. } else {
  8459. out = warehouseOut
  8460. }
  8461. }
  8462. for _, item := range goods {
  8463. var newCount int64 = 0
  8464. for _, it := range goodOne {
  8465. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8466. newCount = it.Count
  8467. }
  8468. }
  8469. prepare := models.DialysisBeforePrepare{
  8470. GoodTypeId: item.GoodTypeId,
  8471. GoodId: item.GoodId,
  8472. Count: item.Count,
  8473. StorehouseId: houseConfig.StorehouseOutInfo,
  8474. }
  8475. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8476. //增加出库数量
  8477. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8478. }
  8479. }
  8480. if len(goods_yc) > 0 {
  8481. for _, good_yc := range goods_yc {
  8482. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8483. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8484. }
  8485. }
  8486. return nil
  8487. }
  8488. // 耗材出库删除
  8489. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8490. // 先根据相关信息查询当天该耗材的出库信息
  8491. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8492. if err != nil {
  8493. return err
  8494. }
  8495. var delete_count int64 = 0
  8496. for _, ware := range warehouseOutInfos {
  8497. // 判断当前出库的数据和删除出库数量
  8498. if good_yc.Count <= ware.Count {
  8499. delete_count = good_yc.Count
  8500. } else {
  8501. delete_count = ware.Count
  8502. }
  8503. warehouseOutInfo := &models.WarehouseOutInfo{
  8504. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8505. WarehouseOutId: warehouseOut.ID,
  8506. Status: 1,
  8507. Ctime: time.Now().Unix(),
  8508. Remark: "",
  8509. OrgId: orgID,
  8510. Type: 1,
  8511. Manufacturer: 0,
  8512. Dealer: 0,
  8513. IsSys: 0,
  8514. SysRecordTime: record_time,
  8515. GoodTypeId: good_yc.GoodTypeId,
  8516. GoodId: good_yc.GoodId,
  8517. StorehouseId: warehouseOut.StorehouseId,
  8518. IsCheck: 1,
  8519. }
  8520. warehouseOutInfo.Count = delete_count
  8521. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8522. warehouseOutInfo.Price = stockInInfo.Price
  8523. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8524. if errOne != nil {
  8525. return errOne
  8526. }
  8527. // 删除出库完成后,要改变流水库存(有疑问)
  8528. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8529. fmt.Println("errOne", errOne)
  8530. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8531. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8532. //扣减出库数量
  8533. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8534. if errThree != nil {
  8535. return errThree
  8536. }
  8537. }
  8538. if good_yc.Count == 0 {
  8539. return nil
  8540. } else {
  8541. return errors.New("退库和出库数据不匹配")
  8542. }
  8543. }
  8544. func (this *DialysisAPIController) GetMobileScheduleList() {
  8545. limit, _ := this.GetInt64("limit")
  8546. page, _ := this.GetInt64("page")
  8547. type_options_visible, _ := this.GetInt64("type_options_visible")
  8548. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8549. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8550. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8551. }
  8552. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8553. newArr = make([]*models.HisPrescriptionProject, 0)
  8554. for i := 0; i < len(arr); i++ {
  8555. repeat := false
  8556. for j := i + 1; j < len(arr); j++ {
  8557. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8558. repeat = true
  8559. break
  8560. }
  8561. }
  8562. if !repeat {
  8563. newArr = append(newArr, arr[i])
  8564. }
  8565. }
  8566. return
  8567. }
  8568. func (this *DialysisAPIController) GetRoleList() {
  8569. admin_user_id, _ := this.GetInt64("admin_user_id")
  8570. orgid := this.GetMobileAdminUserInfo().Org.Id
  8571. list, err := service.GetRoleList(orgid, admin_user_id)
  8572. fmt.Println(err)
  8573. this.ServeSuccessJSON(map[string]interface{}{
  8574. "list": list,
  8575. })
  8576. return
  8577. }
  8578. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8579. // 先根据相关信息查询当天该耗材的出库信息
  8580. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8581. if err != nil {
  8582. return err
  8583. }
  8584. var delete_count int64 = 0
  8585. delete_count = warehouseOutInfos.Count - count
  8586. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8587. // 删除出库完成后,要增加对应批次的库存数量
  8588. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8589. if errThree != nil {
  8590. return errThree
  8591. }
  8592. //增加退库数量
  8593. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8594. //扣减出库数量
  8595. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8596. //查询剩余库存
  8597. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8598. var sum_count int64
  8599. for _, item := range goodList {
  8600. sum_count += item.StockCount
  8601. }
  8602. // 在出库记录表里记录退库详情
  8603. warehouseOutInfo := &models.WarehouseOutInfo{
  8604. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8605. WarehouseOutId: warehouseOut.ID,
  8606. Status: 1,
  8607. Ctime: time.Now().Unix(),
  8608. OrgId: orgID,
  8609. Type: 1,
  8610. IsSys: 1,
  8611. SysRecordTime: record_time,
  8612. GoodTypeId: good_yc.GoodTypeId,
  8613. GoodId: good_yc.GoodId,
  8614. PatientId: good_yc.PatientId,
  8615. ConsumableType: 2,
  8616. StorehouseId: houseConfig.StorehouseOutInfo,
  8617. IsCheck: 1,
  8618. OverCount: sum_count,
  8619. }
  8620. warehouseOutInfo.Count = count
  8621. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8622. warehouseOutInfo.Price = stockInInfo.Price
  8623. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8624. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8625. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8626. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8627. warehouseOutInfo.Number = warehouseOutInfos.Number
  8628. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8629. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8630. //查找当天是否存在出库记录
  8631. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8632. if errcod == gorm.ErrRecordNotFound {
  8633. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8634. //插入详情明细表
  8635. if errOne != nil {
  8636. return errOne
  8637. }
  8638. //插入详情明细表
  8639. stockFlow := models.VmStockFlow{
  8640. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8641. WarehouseOutId: warehouseOut.ID,
  8642. GoodId: good_yc.GoodId,
  8643. Number: warehouseOutInfos.Number,
  8644. ProductDate: stockInInfo.ProductDate,
  8645. ExpireDate: stockInInfo.ExpiryDate,
  8646. Count: count,
  8647. Price: stockInInfo.Price,
  8648. Status: 1,
  8649. Ctime: record_time,
  8650. UserOrgId: good_yc.OrgId,
  8651. Manufacturer: stockInInfo.Manufacturer,
  8652. Dealer: stockInInfo.Dealer,
  8653. LicenseNumber: stockInInfo.LicenseNumber,
  8654. IsEdit: 2,
  8655. Creator: creater,
  8656. SystemTime: record_time,
  8657. ConsumableType: 3,
  8658. WarehousingDetailId: 0,
  8659. IsSys: 1,
  8660. UpdateCreator: creater,
  8661. PatientId: patient_id,
  8662. StorehouseId: houseConfig.StorehouseOutInfo,
  8663. OverCount: sum_count,
  8664. ProjectId: good_yc.ProjectId,
  8665. }
  8666. err := service.CreateStockFlowOne(stockFlow)
  8667. fmt.Println("err", err)
  8668. } else if errcod == nil {
  8669. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8670. }
  8671. //创建退库单
  8672. operation_time := time.Now().Unix()
  8673. //创建退库单
  8674. timeStr := time.Now().Format("2006-01-02")
  8675. timeArr := strings.Split(timeStr, "-")
  8676. total, _ := service.FindAllCancelStockTotal(orgID)
  8677. total = total + 1
  8678. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8679. cancelStock := models.CancelStock{
  8680. OrderNumber: orderNumber,
  8681. OperaTime: operation_time,
  8682. OrgId: orgID,
  8683. Creater: warehouseOut.Creater,
  8684. Ctime: time.Now().Unix(),
  8685. Status: 1,
  8686. ReturnTime: record_time,
  8687. Type: 1,
  8688. StorehouseId: stockInInfo.StorehouseId,
  8689. IsCheck: 1,
  8690. }
  8691. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8692. if msgerrkonde == gorm.ErrRecordNotFound {
  8693. service.AddSigleCancelStock(&cancelStock)
  8694. }
  8695. cancel, _ := service.GetLastCancelStockById(orgID)
  8696. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8697. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8698. cancelStockInfo := models.CancelStockInfo{
  8699. GoodId: stockInInfo.GoodId,
  8700. CancelStockId: cancel.ID,
  8701. GoodTypeId: stockInInfo.GoodTypeId,
  8702. Count: delete_count,
  8703. Price: stockInInfo.PackingPrice,
  8704. Total: 0,
  8705. ProductDate: stockInInfo.ProductDate,
  8706. ExpiryDate: stockInInfo.ExpiryDate,
  8707. Ctime: record_time,
  8708. Status: 1,
  8709. OrgId: orgID,
  8710. OrderNumber: cancel.OrderNumber,
  8711. Type: 0,
  8712. Dealer: deaerler.DealerName,
  8713. Manufacturer: manufacturer.ManufacturerName,
  8714. Number: stockInInfo.Number,
  8715. RegisterAccount: "",
  8716. Remark: "",
  8717. WarehouseInfoId: stockInInfo.ID,
  8718. PatientId: patient_id,
  8719. RecordDate: record_time,
  8720. StorehouseId: stockInInfo.StorehouseId,
  8721. IsCheck: 1,
  8722. }
  8723. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8724. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8725. flow := models.VmStockFlow{
  8726. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8727. GoodId: good_yc.GoodId,
  8728. Number: warehouseOutInfos.Number,
  8729. LicenseNumber: stockInInfo.LicenseNumber,
  8730. Count: delete_count,
  8731. UserOrgId: orgID,
  8732. PatientId: patient_id,
  8733. SystemTime: record_time,
  8734. ConsumableType: 7,
  8735. IsSys: 0,
  8736. WarehousingOrder: "",
  8737. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8738. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8739. IsEdit: 0,
  8740. CancelStockId: cancel.ID,
  8741. CancelOrderNumber: cancel.OrderNumber,
  8742. Manufacturer: manufacturer.ID,
  8743. Dealer: 0,
  8744. Creator: warehouseOut.Creater,
  8745. UpdateCreator: 0,
  8746. Status: 1,
  8747. Ctime: record_time,
  8748. Mtime: 0,
  8749. Price: stockInInfo.Price,
  8750. WarehousingDetailId: stockInInfo.ID,
  8751. WarehouseOutDetailId: warehouseOutInfos.ID,
  8752. CancelOutDetailId: cancelInfo.ID,
  8753. ProductDate: stockInInfo.ProductDate,
  8754. ExpireDate: stockInInfo.ExpiryDate,
  8755. StorehouseId: houseConfig.StorehouseOutInfo,
  8756. OverCount: sum_count,
  8757. }
  8758. service.CreateStockFlowOne(flow)
  8759. //更改自动出库的表格
  8760. details := models.BloodAutomaticReduceDetail{
  8761. WarehouseOutId: warehouseOutInfo.ID,
  8762. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8763. PatientId: patient_id,
  8764. Ctime: time.Now().Unix(),
  8765. Mtime: time.Now().Unix(),
  8766. Status: 1,
  8767. RecordTime: record_time,
  8768. OrgId: orgID,
  8769. GoodId: good_yc.GoodId,
  8770. GoodTypeId: good_yc.GoodTypeId,
  8771. Count: count,
  8772. StorehouseId: houseConfig.StorehouseOutInfo,
  8773. }
  8774. //查询当天耗材是否已经存在数据
  8775. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8776. if errcode == gorm.ErrRecordNotFound {
  8777. errTwo := service.CreateAutoReduceRecord(&details)
  8778. if errTwo != nil {
  8779. return errTwo
  8780. }
  8781. } else if errcode == nil {
  8782. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8783. service.CreateAutoReduceRecord(&details)
  8784. }
  8785. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8786. //增加出库库存数量
  8787. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8788. if good_yc.Count == 0 {
  8789. return nil
  8790. } else {
  8791. return errors.New("退库和出库数据不匹配")
  8792. }
  8793. }
  8794. func (this *DialysisAPIController) SavePatientSign() {
  8795. adminUserInfo := this.GetMobileAdminUserInfo()
  8796. patient_id, _ := this.GetInt64("patient_id")
  8797. dialysis_date, _ := this.GetInt64("dialysis_date")
  8798. orgid := adminUserInfo.Org.Id
  8799. var esdata models.DialysisOrder
  8800. var err error
  8801. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8802. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8803. return
  8804. }
  8805. esdata.Hash = esdata.Hash
  8806. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8807. order := models.DialysisOrder{
  8808. Hash: esdata.Hash,
  8809. Url: esdata.Url,
  8810. }
  8811. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8812. redis := service.RedisClient()
  8813. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8814. redis.Set(key, "", time.Second)
  8815. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8816. //清空key 值
  8817. redis.Set(keyOne, "", time.Second)
  8818. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8819. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8820. //redis.Set(keyTwo, "", time.Second)
  8821. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8822. redis.Set(keyThree, "", time.Second)
  8823. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8824. redis.Set(keyFour, "", time.Second)
  8825. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8826. redis.Set(keyFive, "", time.Second)
  8827. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8828. redis.Set(keySix, "", time.Second)
  8829. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8830. redis.Set(keySeven, "", time.Second)
  8831. if err != nil {
  8832. fmt.Println(err)
  8833. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8834. return
  8835. }
  8836. this.ServeSuccessJSON(map[string]interface{}{
  8837. "electronic_signature": esdata,
  8838. })
  8839. }
  8840. func (this *DialysisAPIController) GetPatientSign() {
  8841. patient_id, _ := this.GetInt64("patient_id")
  8842. dialysis_date, _ := this.GetInt64("dialysis_date")
  8843. adminUserInfo := this.GetMobileAdminUserInfo()
  8844. orgId := adminUserInfo.Org.Id
  8845. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8846. if err != nil {
  8847. fmt.Println(err)
  8848. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8849. return
  8850. }
  8851. this.ServeSuccessJSON(map[string]interface{}{
  8852. "dialysisOrder": dialysisOrder,
  8853. })
  8854. }
  8855. func (this *DialysisAPIController) GetScheduleByPatient() {
  8856. patient_id, _ := this.GetInt64("patient_id")
  8857. schedule_date, _ := this.GetInt64("schedule_date")
  8858. orgid := this.GetMobileAdminUserInfo().Org.Id
  8859. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8860. this.ServeSuccessJSON(map[string]interface{}{
  8861. "schedule": schedule,
  8862. })
  8863. }
  8864. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8865. org_id := this.GetMobileAdminUserInfo().Org.Id
  8866. patient_id, _ := this.GetInt64("patient_id")
  8867. schedule_date, _ := this.GetInt64("schedule_date")
  8868. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8869. this.ServeSuccessJSON(map[string]interface{}{
  8870. "order": order,
  8871. })
  8872. }
  8873. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8874. org_id := this.GetMobileAdminUserInfo().Org.Id
  8875. schedule_date := this.GetString("schedule_date")
  8876. schedule_type, _ := this.GetInt64("schedule_type")
  8877. timeLayout := "2006-01-02"
  8878. loc, _ := time.LoadLocation("Local")
  8879. var startdateunix int64
  8880. if len(schedule_date) > 0 {
  8881. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8882. if err != nil {
  8883. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8884. return
  8885. }
  8886. startdateunix = theTime.Unix()
  8887. }
  8888. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8889. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8890. devices, _ := service.GetAllDevicetByListSix(org_id)
  8891. for key, item := range scheduals {
  8892. // 床位信息
  8893. for _, device := range devices {
  8894. if item.BedId == device.ID {
  8895. scheduals[key].DeviceNumber = device
  8896. break
  8897. }
  8898. }
  8899. }
  8900. this.ServeSuccessJSON(map[string]interface{}{
  8901. "list": list,
  8902. "scheduals": scheduals,
  8903. })
  8904. }
  8905. func (this *DialysisAPIController) SavePatientPicture() {
  8906. patient_id, _ := this.GetInt64("patient_id")
  8907. dialysis_date, _ := this.GetInt64("schedule_date")
  8908. avatar := this.GetString("avatar")
  8909. fmt.Println("patient_id", patient_id)
  8910. orgId := this.GetMobileAdminUserInfo().Org.Id
  8911. order := models.DialysisOrder{
  8912. Url: avatar,
  8913. }
  8914. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8915. redis := service.RedisClient()
  8916. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8917. redis.Set(key, "", time.Second)
  8918. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8919. //清空key 值
  8920. redis.Set(keyOne, "", time.Second)
  8921. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8922. redis.Set(keyThree, "", time.Second)
  8923. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8924. redis.Set(keyFour, "", time.Second)
  8925. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8926. redis.Set(keyFive, "", time.Second)
  8927. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8928. redis.Set(keySix, "", time.Second)
  8929. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8930. redis.Set(keySeven, "", time.Second)
  8931. if err != nil {
  8932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8933. return
  8934. }
  8935. this.ServeSuccessJSON(map[string]interface{}{
  8936. "order": order,
  8937. })
  8938. }
  8939. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8940. ids := this.GetString("ids")
  8941. idSplit := strings.Split(ids, ",")
  8942. orgId := this.GetMobileAdminUserInfo().Org.Id
  8943. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8944. execution_time := this.GetString("exce_time")
  8945. timeLayout2 := "2006-01-02 15:04:05"
  8946. loc, _ := time.LoadLocation("Local")
  8947. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8948. if errs != nil {
  8949. utils.ErrorLog(errs.Error())
  8950. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8951. return
  8952. }
  8953. //his客户
  8954. if config.IsOpen == 1 {
  8955. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8956. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8957. for _, item := range list {
  8958. for _, it := range adviceList {
  8959. if item.DrugId == it.DrugId {
  8960. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8961. }
  8962. }
  8963. }
  8964. for _, item := range list {
  8965. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8966. var sum_out_count int64
  8967. for _, itemThree := range item.ChildDoctorAdvice {
  8968. var prescribing_number int64
  8969. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8970. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8971. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8972. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8973. }
  8974. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8975. prescribing_number = parseIntPrescribingNumber
  8976. }
  8977. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8978. prescribing_number = parseIntPrescribingNumber
  8979. }
  8980. sum_out_count += prescribing_number
  8981. }
  8982. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8983. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8984. //库存不足
  8985. if sum_out_count > drugStockOut.FlushCount {
  8986. this.ServeSuccessJSON(map[string]interface{}{
  8987. "msg": "2",
  8988. "drug": medical,
  8989. "ids": ids,
  8990. })
  8991. return
  8992. }
  8993. }
  8994. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8995. //执行医嘱
  8996. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8997. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8998. for _, item := range advices {
  8999. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9000. redis := service.RedisClient()
  9001. //清空key 值
  9002. redis.Set(key, "", time.Second)
  9003. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9004. redis.Set(keyTwo, "", time.Second)
  9005. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9006. redis.Set(keyThree, "", time.Second)
  9007. recordDate := theTime.Format("2006-01-02")
  9008. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9009. redis.Set(keyFour, "", time.Second)
  9010. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9011. redis.Set(keyFive, "", time.Second)
  9012. defer redis.Close()
  9013. }
  9014. if errs == nil {
  9015. //药品管理信息
  9016. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9017. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9018. if drugStockConfig.IsOpen == 1 {
  9019. for _, item := range advices {
  9020. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9021. config, _ := service.GetDrugOpenConfigOne(orgId)
  9022. if config.IsOpen != 1 {
  9023. //查询该药品是否有库存
  9024. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9025. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9026. if medical.IsUse == 2 {
  9027. if config.IsOpen != 1 {
  9028. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9029. service.HisDrugsDelivery(orgId, creater, &advice)
  9030. if orgId == 3877 || orgId == 10265 {
  9031. //查询该药品是否有出库记录
  9032. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9033. if len(flowMap) == 0 {
  9034. errs := service.UpdateHisAdviceById(advice.ID)
  9035. if errs != nil {
  9036. drugError := models.XtDrugError{
  9037. UserOrgId: orgId,
  9038. DrugId: item.DrugId,
  9039. RecordDate: item.AdviceDate,
  9040. PatientId: item.PatientId,
  9041. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9042. Status: 1,
  9043. Ctime: time.Now().Unix(),
  9044. Mtime: 0,
  9045. SumCount: 0,
  9046. Prescribingnumber: advice.PrescribingNumber,
  9047. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9048. }
  9049. service.CreateDrugError(drugError)
  9050. }
  9051. this.ServeSuccessJSON(map[string]interface{}{
  9052. "msg": "2",
  9053. "drug": medical,
  9054. "ids": ids,
  9055. })
  9056. return
  9057. }
  9058. }
  9059. }
  9060. if pharmacyConfig.IsOpen != 1 {
  9061. service.HisDrugsDelivery(orgId, creater, &advice)
  9062. if orgId == 3877 || orgId == 10265 {
  9063. //查询该药品是否有出库记录
  9064. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9065. if len(flowMap) == 0 {
  9066. errs := service.UpdateHisAdviceById(advice.ID)
  9067. if errs != nil {
  9068. drugError := models.XtDrugError{
  9069. UserOrgId: orgId,
  9070. DrugId: item.DrugId,
  9071. RecordDate: item.AdviceDate,
  9072. PatientId: item.PatientId,
  9073. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9074. Status: 1,
  9075. Ctime: time.Now().Unix(),
  9076. Mtime: 0,
  9077. SumCount: 0,
  9078. Prescribingnumber: advice.PrescribingNumber,
  9079. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9080. }
  9081. service.CreateDrugError(drugError)
  9082. }
  9083. this.ServeSuccessJSON(map[string]interface{}{
  9084. "msg": "2",
  9085. "drug": medical,
  9086. "ids": ids,
  9087. })
  9088. return
  9089. }
  9090. }
  9091. }
  9092. //更新字典里面的库存
  9093. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9094. var sum_count int64
  9095. for _, its := range stockInfo {
  9096. if its.MaxUnit == medical.MaxUnit {
  9097. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9098. }
  9099. sum_count += its.StockMaxNumber + its.StockMinNumber
  9100. }
  9101. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9102. //剩余库存
  9103. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9104. }
  9105. }
  9106. }
  9107. }
  9108. }
  9109. this.ServeSuccessJSON(map[string]interface{}{
  9110. "msg": "1",
  9111. "ids": ids,
  9112. })
  9113. return
  9114. } else {
  9115. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9116. }
  9117. }
  9118. //血透客户
  9119. if config.IsOpen == 2 || config.IsOpen == 0 {
  9120. //药品管理信息
  9121. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9122. if drugStockConfig.IsOpen == 1 {
  9123. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9124. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9125. for _, item := range list {
  9126. for _, it := range adviceList {
  9127. if item.DrugId == it.DrugId {
  9128. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9129. }
  9130. }
  9131. }
  9132. for _, item := range list {
  9133. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9134. var sum_out_count int64
  9135. for _, itemThree := range item.ChildDoctorAdvice {
  9136. var prescribing_number int64
  9137. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9138. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9139. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9140. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9141. }
  9142. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9143. prescribing_number = parseIntPrescribingNumber
  9144. }
  9145. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9146. prescribing_number = parseIntPrescribingNumber
  9147. }
  9148. sum_out_count += prescribing_number
  9149. }
  9150. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9151. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9152. //库存不足
  9153. if sum_out_count > drugStockOut.FlushCount {
  9154. this.ServeSuccessJSON(map[string]interface{}{
  9155. "msg": "2",
  9156. "drug": medical,
  9157. "ids": ids,
  9158. })
  9159. return
  9160. }
  9161. }
  9162. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9163. //执行医嘱
  9164. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9165. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9166. for _, item := range advices {
  9167. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9168. redis := service.RedisClient()
  9169. //清空key 值
  9170. redis.Set(key, "", time.Second)
  9171. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9172. redis.Set(keyTwo, "", time.Second)
  9173. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9174. redis.Set(keyThree, "", time.Second)
  9175. recordDate := theTime.Format("2006-01-02")
  9176. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9177. redis.Set(keyFour, "", time.Second)
  9178. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9179. redis.Set(keyFive, "", time.Second)
  9180. defer redis.Close()
  9181. }
  9182. if errs == nil {
  9183. for _, item := range advices {
  9184. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9185. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9186. //查询是否出库按钮开启
  9187. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9188. if adviceSetting.IsAdviceOpen == 1 {
  9189. //查询是否出库按钮开启
  9190. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9191. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9192. if prescriptionConfig.IsOpen == 1 {
  9193. if medical.IsUse == 2 {
  9194. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9195. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9196. }
  9197. if pharmacyConfig.IsOpen != 1 {
  9198. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9199. }
  9200. //更新字典里面的库存
  9201. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9202. var sum_count int64
  9203. for _, its := range stockInfo {
  9204. if its.MaxUnit == medical.MaxUnit {
  9205. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9206. }
  9207. sum_count += its.StockMaxNumber + its.StockMinNumber
  9208. }
  9209. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9210. //剩余库存
  9211. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9212. }
  9213. }
  9214. } else {
  9215. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9216. if medical.IsUse == 2 {
  9217. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9218. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9219. }
  9220. if pharmacyConfig.IsOpen != 1 {
  9221. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9222. }
  9223. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9224. var sum_count int64
  9225. for _, its := range stockInfo {
  9226. if its.MaxUnit == medical.MaxUnit {
  9227. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9228. }
  9229. sum_count += its.StockMaxNumber + its.StockMinNumber
  9230. }
  9231. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9232. //剩余库存
  9233. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9234. }
  9235. }
  9236. }
  9237. }
  9238. this.ServeSuccessJSON(map[string]interface{}{
  9239. "msg": "1",
  9240. "ids": ids,
  9241. })
  9242. return
  9243. } else {
  9244. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9245. //执行医嘱
  9246. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9247. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9248. for _, item := range advices {
  9249. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9250. redis := service.RedisClient()
  9251. //清空key 值
  9252. redis.Set(key, "", time.Second)
  9253. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9254. redis.Set(keyTwo, "", time.Second)
  9255. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9256. redis.Set(keyThree, "", time.Second)
  9257. recordDate := theTime.Format("2006-01-02")
  9258. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9259. redis.Set(keyFour, "", time.Second)
  9260. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9261. redis.Set(keyFive, "", time.Second)
  9262. defer redis.Close()
  9263. }
  9264. this.ServeSuccessJSON(map[string]interface{}{
  9265. "msg": "1",
  9266. "ids": ids,
  9267. })
  9268. return
  9269. }
  9270. }
  9271. }
  9272. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9273. ids := this.GetString("ids")
  9274. idSplit := strings.Split(ids, ",")
  9275. orgId := this.GetMobileAdminUserInfo().Org.Id
  9276. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9277. if config.IsOpen == 1 {
  9278. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9279. this.ServeSuccessJSON(map[string]interface{}{
  9280. "msg": "1",
  9281. "ids": ids,
  9282. })
  9283. return
  9284. }
  9285. if config.IsOpen == 0 || config.IsOpen == 2 {
  9286. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9287. this.ServeSuccessJSON(map[string]interface{}{
  9288. "msg": "1",
  9289. "ids": ids,
  9290. })
  9291. return
  9292. }
  9293. }
  9294. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9295. ids := this.GetString("ids")
  9296. idSplit := strings.Split(ids, ",")
  9297. orgId := this.GetMobileAdminUserInfo().Org.Id
  9298. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9299. //his
  9300. if config.IsOpen == 1 {
  9301. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9302. theTime := time.Now()
  9303. advices := models.HisDoctorAdviceThirty{
  9304. CheckTime: theTime.Unix(),
  9305. Checker: checker,
  9306. UpdatedTime: time.Now().Unix(),
  9307. }
  9308. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9309. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9310. for _, item := range list {
  9311. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9312. redis := service.RedisClient()
  9313. //清空key 值
  9314. redis.Set(key, "", time.Second)
  9315. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9316. redis.Set(keyTwo, "", time.Second)
  9317. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9318. redis.Set(keyThree, "", time.Second)
  9319. recordDate := theTime.Format("2006-01-02")
  9320. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9321. redis.Set(keyFour, "", time.Second)
  9322. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9323. redis.Set(keyFive, "", time.Second)
  9324. defer redis.Close()
  9325. }
  9326. this.ServeSuccessJSON(map[string]interface{}{
  9327. "msg": "1",
  9328. "ids": ids,
  9329. })
  9330. return
  9331. }
  9332. //血透
  9333. if config.IsOpen == 0 || config.IsOpen == 2 {
  9334. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9335. theTime := time.Now()
  9336. advices := models.DoctorAdvice{
  9337. CheckTime: theTime.Unix(),
  9338. Checker: checker,
  9339. UpdatedTime: time.Now().Unix(),
  9340. }
  9341. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9342. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9343. for _, item := range list {
  9344. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9345. redis := service.RedisClient()
  9346. //清空key 值
  9347. redis.Set(key, "", time.Second)
  9348. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9349. redis.Set(keyTwo, "", time.Second)
  9350. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9351. redis.Set(keyThree, "", time.Second)
  9352. recordDate := theTime.Format("2006-01-02")
  9353. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9354. redis.Set(keyFour, "", time.Second)
  9355. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9356. redis.Set(keyFive, "", time.Second)
  9357. defer redis.Close()
  9358. }
  9359. this.ServeSuccessJSON(map[string]interface{}{
  9360. "msg": "1",
  9361. "ids": ids,
  9362. })
  9363. return
  9364. }
  9365. }
  9366. func (this *DialysisAPIController) CheckSchedule() {
  9367. patientID, _ := this.GetInt64("patient_id")
  9368. recordDateStr := this.GetString("record_date")
  9369. nurseID, _ := this.GetInt64("start_nurse")
  9370. schedual_type, _ := this.GetInt64("schedual_type")
  9371. bedID, _ := this.GetInt64("bed")
  9372. start_time := this.GetString("start_time")
  9373. fmt.Println("patientID", patientID)
  9374. fmt.Println("recordDateStr", recordDateStr)
  9375. fmt.Println("nurseID", nurseID)
  9376. fmt.Println("schedual_type------", schedual_type)
  9377. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9378. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9379. return
  9380. }
  9381. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9382. if parseStartDateErr != nil {
  9383. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9384. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9385. return
  9386. }
  9387. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9388. if parseErr != nil {
  9389. this.ErrorLog("时间解析失败:%v", parseErr)
  9390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9391. return
  9392. }
  9393. adminUserInfo := this.GetMobileAdminUserInfo()
  9394. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9395. if getPatientErr != nil {
  9396. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9397. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9398. return
  9399. } else if patient == nil {
  9400. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9401. return
  9402. }
  9403. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9404. if getNurseErr != nil {
  9405. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9406. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9407. return
  9408. } else if nurse == nil {
  9409. this.ErrorLog("护士不存在")
  9410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9411. return
  9412. }
  9413. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9414. if getDeviceNumberErr != nil {
  9415. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9416. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9417. return
  9418. } else if deviceNumber == nil {
  9419. this.ErrorLog("床位号不存在")
  9420. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9421. return
  9422. }
  9423. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9424. if getRecordErr != nil {
  9425. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9426. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9427. return
  9428. } else if dialysisRecord != nil {
  9429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9430. return
  9431. }
  9432. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9433. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9434. timeLayout := "2006-01-02 15:04:05"
  9435. loc, _ := time.LoadLocation("Local")
  9436. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9437. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9438. schedulestartTime := theStartTime.Unix()
  9439. scheduleendTime := theEndTime.Unix()
  9440. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9441. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9442. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9443. //查询该床位是否有人用了
  9444. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9445. if err == nil {
  9446. if schedule.ID == 0 {
  9447. this.ServeSuccessJSON(map[string]interface{}{
  9448. "status": 0,
  9449. "msg": "请求失败",
  9450. })
  9451. } else {
  9452. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9453. if order.ID > 0 { //该机位被其他人占用了
  9454. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9455. return
  9456. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9457. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9458. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9459. this.ServeSuccessJSON(map[string]interface{}{
  9460. "status": 1,
  9461. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9462. })
  9463. return
  9464. } else {
  9465. this.ServeSuccessJSON(map[string]interface{}{
  9466. "status": 0,
  9467. "msg": "",
  9468. })
  9469. }
  9470. }
  9471. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9472. this.ServeSuccessJSON(map[string]interface{}{
  9473. "status": 2,
  9474. "msg": "当前机位已有患者在使用,请重新选择!",
  9475. })
  9476. }
  9477. }
  9478. } else {
  9479. this.ServeSuccessJSON(map[string]interface{}{
  9480. "status": 0,
  9481. "msg": "",
  9482. })
  9483. }
  9484. }
  9485. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9486. orgId := this.GetMobileAdminUserInfo().Org.Id
  9487. schedule_type, _ := this.GetInt64("schedule_type")
  9488. partion_type, _ := this.GetInt64("partion_type")
  9489. start_time := this.GetString("start_time")
  9490. timeLayout := "2006-01-02"
  9491. loc, _ := time.LoadLocation("Local")
  9492. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9493. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9494. _, config := service.FindXTHisRecordByOrgId(orgId)
  9495. appId := this.GetMobileAdminUserInfo().App.Id
  9496. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9497. if err == nil {
  9498. this.ServeSuccessJSON(map[string]interface{}{
  9499. "list": list,
  9500. "config": config,
  9501. "doctorList": doctorList,
  9502. })
  9503. return
  9504. } else {
  9505. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9506. return
  9507. }
  9508. }
  9509. func (this *DialysisAPIController) SaveMobileInformation() {
  9510. patient_id, _ := this.GetInt64("patient_id")
  9511. record_date, _ := this.GetInt64("record_date")
  9512. startTime := this.GetString("start_time")
  9513. module, _ := this.GetInt64("module")
  9514. remark := this.GetString("remark")
  9515. timeLayout := "2006-01-02 15:04"
  9516. loc, _ := time.LoadLocation("Local")
  9517. if len(startTime) == 0 {
  9518. utils.ErrorLog("len(start_time) == 0")
  9519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9520. return
  9521. }
  9522. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9523. if err != nil {
  9524. utils.ErrorLog(err.Error())
  9525. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9526. return
  9527. }
  9528. StartTime := theTime.Unix()
  9529. fmt.Println("startime-------------", StartTime)
  9530. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9531. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9532. information := models.XtDialysisInformation{
  9533. Module: module,
  9534. PatientId: patient_id,
  9535. RecordDate: record_date,
  9536. ApplicationDate: StartTime,
  9537. Creater: creater,
  9538. ApplicationStatus: 2,
  9539. Checker: 0,
  9540. CheckTime: 0,
  9541. Remark: remark,
  9542. UserOrgId: user_org_id,
  9543. Ctime: time.Now().Unix(),
  9544. Status: 1,
  9545. Mtime: 0,
  9546. }
  9547. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9548. if infor.ID == 0 {
  9549. service.SaveDialysisInformation(information)
  9550. }
  9551. if infor.ID > 0 {
  9552. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9553. }
  9554. this.ServeSuccessJSON(map[string]interface{}{
  9555. "information": information,
  9556. })
  9557. return
  9558. }
  9559. func (this *DialysisAPIController) GetMobileInformation() {
  9560. limit, _ := this.GetInt64("limit")
  9561. page, _ := this.GetInt64("page")
  9562. orgid := this.GetMobileAdminUserInfo().Org.Id
  9563. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9564. appid := this.GetMobileAdminUserInfo().App.Id
  9565. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9566. patients, _ := service.GetAllpatientThirty(orgid)
  9567. this.ServeSuccessJSON(map[string]interface{}{
  9568. "information": information,
  9569. "total": total,
  9570. "doclist": doclist,
  9571. "patients": patients,
  9572. })
  9573. return
  9574. }
  9575. func (this *DialysisAPIController) GetMobileInformationOne() {
  9576. limit, _ := this.GetInt64("limit")
  9577. page, _ := this.GetInt64("page")
  9578. orgid := this.GetMobileAdminUserInfo().Org.Id
  9579. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9580. appid := this.GetMobileAdminUserInfo().App.Id
  9581. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9582. patients, _ := service.GetAllpatientThirty(orgid)
  9583. this.ServeSuccessJSON(map[string]interface{}{
  9584. "information": information,
  9585. "total": total,
  9586. "doclist": doclist,
  9587. "patients": patients,
  9588. })
  9589. return
  9590. }
  9591. func (this *DialysisAPIController) CheckMobileInformation() {
  9592. id, _ := this.GetInt64("id")
  9593. application_status, _ := this.GetInt64("application_status")
  9594. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9595. checktime := time.Now().Unix()
  9596. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9597. if err == nil {
  9598. this.ServeSuccessJSON(map[string]interface{}{
  9599. "msg": "ok",
  9600. })
  9601. return
  9602. }
  9603. }
  9604. func (c *DialysisAPIController) GetControlMonitorList() {
  9605. partition, _ := c.GetInt64("partition")
  9606. monitorDate := c.GetString("date")
  9607. patient_id, _ := c.GetInt64("patient_id")
  9608. pat_type, _ := c.GetInt64("pat_type")
  9609. timeLayout := "2006-01-02"
  9610. loc, _ := time.LoadLocation("Local")
  9611. var theStartTime int64
  9612. if len(monitorDate) > 0 {
  9613. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9614. if err != nil {
  9615. theStartTime = 0
  9616. }
  9617. theStartTime = theTime.Unix()
  9618. }
  9619. adminInfo := c.GetMobileAdminUserInfo()
  9620. orgID := adminInfo.Org.Id
  9621. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9622. if err != nil {
  9623. c.ErrorLog("获取排班信息失败:%v", err)
  9624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9625. } else {
  9626. if len(monitor) > 0 {
  9627. //获取所有床位
  9628. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9629. //获取所有分区
  9630. zoneList, _ := service.GetAllZoneByList(orgID)
  9631. //获取透析处方
  9632. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9633. //获取透前评估
  9634. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9635. //获取上机
  9636. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9637. //获取透后
  9638. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9639. //获取透后监测
  9640. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9641. //获取所有的患者
  9642. patients, _ := service.GetAllPatientListByListOne(orgID)
  9643. //获取所有透析模式
  9644. treatments, _ := service.GetAllTreatModeByList(orgID)
  9645. //获取所有医嘱
  9646. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9647. //获取双人核对
  9648. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9649. //治疗小结
  9650. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9651. //待消毒
  9652. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9653. for key, item := range monitor {
  9654. // 获取床位信息
  9655. for _, it := range numberList {
  9656. if item.BedId == it.ID {
  9657. monitor[key].DeviceNumber = it
  9658. break
  9659. }
  9660. }
  9661. //获取分区信息
  9662. for _, it := range zoneList {
  9663. if item.PartitionId == it.ID {
  9664. monitor[key].DeviceZone = it
  9665. }
  9666. }
  9667. for _, prescription := range prescriptions {
  9668. if item.PatientId == prescription.PatientId {
  9669. monitor[key].Prescription = prescription
  9670. break
  9671. }
  9672. }
  9673. for _, it := range checkList {
  9674. if item.PatientId == it.PatientId {
  9675. monitor[key].DoubleCheck = it
  9676. break
  9677. }
  9678. }
  9679. for _, it := range summaryList {
  9680. if item.PatientId == it.PatientId {
  9681. monitor[key].TreatmentSummaryForList = it
  9682. break
  9683. }
  9684. }
  9685. // 透前评估
  9686. for _, assessmentBefore := range assessmentBefores {
  9687. if item.PatientId == assessmentBefore.PatientId {
  9688. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9689. break
  9690. }
  9691. }
  9692. // 透析上下机
  9693. for _, dialysisOrder := range dialysisOrders {
  9694. if item.PatientId == dialysisOrder.PatientId {
  9695. monitor[key].DialysisOrder = dialysisOrder
  9696. break
  9697. }
  9698. }
  9699. // 治疗小节
  9700. for _, afterDislysis := range AssessmentAfterDislysis {
  9701. if item.PatientId == afterDislysis.PatientId {
  9702. monitor[key].AssessmentAfterDislysis = afterDislysis
  9703. break
  9704. }
  9705. }
  9706. for _, it := range monitorlist {
  9707. if item.PatientId == it.PatientId {
  9708. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9709. }
  9710. }
  9711. for _, it := range adviceList {
  9712. if item.PatientId == it.PatientId {
  9713. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9714. }
  9715. }
  9716. for _, patient := range patients {
  9717. if item.PatientId == patient.ID {
  9718. monitor[key].MonitorPatients = patient
  9719. break
  9720. }
  9721. }
  9722. for _, treatment := range treatments {
  9723. if item.ModeId == treatment.ID {
  9724. monitor[key].TreatmentMode = treatment
  9725. break
  9726. }
  9727. }
  9728. for _, infor := range informationList {
  9729. if item.PatientId == infor.PatientId {
  9730. monitor[key].NewDeviceInformation = infor
  9731. break
  9732. }
  9733. }
  9734. }
  9735. }
  9736. }
  9737. patients, err := service.GetAllpatientFourty(orgID)
  9738. var mds []*models.NewMonitorDialysisScheduleList
  9739. if pat_type == 0 {
  9740. for _, item := range monitor {
  9741. mds = append(mds, item)
  9742. }
  9743. }
  9744. //待医嘱核对
  9745. if pat_type == 1 {
  9746. for _, item := range monitor {
  9747. if len(item.AdviceList) > 0 {
  9748. mds = append(mds, item)
  9749. }
  9750. }
  9751. }
  9752. //待开小结
  9753. if pat_type == 2 {
  9754. for _, item := range monitor {
  9755. if item.TreatmentSummaryForList == nil {
  9756. mds = append(mds, item)
  9757. }
  9758. }
  9759. }
  9760. //待下机
  9761. if pat_type == 3 {
  9762. for _, item := range monitor {
  9763. if item.DialysisOrder != nil {
  9764. if item.DialysisOrder.ID > 0 {
  9765. mds = append(mds, item)
  9766. }
  9767. }
  9768. }
  9769. }
  9770. //待消毒
  9771. if pat_type == 4 {
  9772. for _, item := range monitor {
  9773. if item.NewDeviceInformation == nil {
  9774. mds = append(mds, item)
  9775. }
  9776. }
  9777. }
  9778. //待双人核对
  9779. if pat_type == 5 {
  9780. for _, item := range monitor {
  9781. if item.DoubleCheck == nil {
  9782. mds = append(mds, item)
  9783. }
  9784. }
  9785. }
  9786. //医嘱未执行
  9787. if pat_type == 6 {
  9788. for _, item := range monitor {
  9789. if len(item.AdviceList) > 0 {
  9790. mds = append(mds, item)
  9791. }
  9792. }
  9793. }
  9794. //患者未签名
  9795. if pat_type == 7 {
  9796. for _, item := range monitor {
  9797. if item.DialysisOrder != nil {
  9798. if item.DialysisOrder.ID > 0 {
  9799. mds = append(mds, item)
  9800. }
  9801. }
  9802. }
  9803. }
  9804. //目标超滤于实际超滤不同
  9805. if pat_type == 8 {
  9806. for _, item := range monitor {
  9807. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9808. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9809. mds = append(mds, item)
  9810. }
  9811. }
  9812. }
  9813. }
  9814. //血压少于5次
  9815. if pat_type == 9 {
  9816. for _, item := range monitor {
  9817. if len(item.MonitoringRecord) < 5 {
  9818. mds = append(mds, item)
  9819. }
  9820. }
  9821. }
  9822. if pat_type == 10 {
  9823. for _, item := range monitor {
  9824. if len(item.MonitoringRecord) == 0 {
  9825. mds = append(mds, item)
  9826. }
  9827. }
  9828. }
  9829. if pat_type == 11 {
  9830. for _, item := range monitor {
  9831. if len(item.MonitoringRecord) > 0 {
  9832. mds = append(mds, item)
  9833. }
  9834. }
  9835. }
  9836. if pat_type == 12 {
  9837. for _, item := range monitor {
  9838. if len(item.MonitoringRecord) > 0 {
  9839. mds = append(mds, item)
  9840. }
  9841. }
  9842. }
  9843. if err == nil {
  9844. c.ServeSuccessJSON(map[string]interface{}{
  9845. "monitor": mds,
  9846. "patients": patients,
  9847. })
  9848. } else {
  9849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9850. }
  9851. }
  9852. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9853. admin_user_id, _ := c.GetInt64("admin_user_id")
  9854. timeStr := time.Now().Format("2006-01-02")
  9855. timeLayout := "2006-01-02 15:04:05"
  9856. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9857. timenow := timeStringToTime.Unix()
  9858. orgId := c.GetMobileAdminUserInfo().Org.Id
  9859. //查询当前护士的患者
  9860. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9861. var patientIds []int64
  9862. for _, item := range orderList {
  9863. patientIds = append(patientIds, item.PatientId)
  9864. }
  9865. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9866. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9867. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9868. //药品管理信息
  9869. _, drugStockConfig := service.FindHisConfig(orgId)
  9870. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9871. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9872. c.ServeSuccessJSON(map[string]interface{}{
  9873. "adviceList": adviceList,
  9874. "hisAdviceList": hisAdviceList,
  9875. "projectList": projectList,
  9876. "drugStockConfig": drugStockConfig,
  9877. "patientList": patientList,
  9878. "projectConfig": projectConfig,
  9879. })
  9880. }
  9881. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9882. patient_id, _ := c.GetInt64("patient_id")
  9883. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9884. c.ServeSuccessJSON(map[string]interface{}{
  9885. "recrods": recrods,
  9886. })
  9887. }
  9888. func (c *DialysisAPIController) ExMobileChangeSch() {
  9889. id_one, _ := c.GetInt64("id_one")
  9890. id_two, _ := c.GetInt64("id_two")
  9891. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9892. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9893. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9894. //if order2.ID > 0 {
  9895. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9896. // return
  9897. //}
  9898. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9899. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9900. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9901. if count > 0 {
  9902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9903. return
  9904. }
  9905. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9906. if count1 > 0 {
  9907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9908. return
  9909. }
  9910. }
  9911. err := service.UpdateScheduleThree(sch, sch_two)
  9912. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9913. if order.ID > 0 {
  9914. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9915. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9916. redis := service.RedisClient()
  9917. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9918. redis.Set(key, "", time.Second)
  9919. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9920. //清空key 值
  9921. redis.Set(keyOne, "", time.Second)
  9922. }
  9923. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  9924. if orderOne.ID > 0 {
  9925. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  9926. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9927. redis := service.RedisClient()
  9928. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9929. redis.Set(key, "", time.Second)
  9930. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9931. //清空key 值
  9932. redis.Set(keyOne, "", time.Second)
  9933. }
  9934. if err == nil {
  9935. //去除当天患者排班中重复数据,保留最后一条数据
  9936. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9937. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9938. c.ServeSuccessJSON(map[string]interface{}{
  9939. "msg": "交换成功",
  9940. })
  9941. } else {
  9942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9943. return
  9944. }
  9945. }
  9946. func (c *DialysisAPIController) MobileCoverSch() {
  9947. id_one, _ := c.GetInt64("id_one")
  9948. id_two, _ := c.GetInt64("id_two")
  9949. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9950. //针对凤凰医院
  9951. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9952. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9953. if len(advice) > 0 {
  9954. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9955. }
  9956. }
  9957. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9958. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9959. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9960. if len(hisAdvice) > 0 {
  9961. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9962. }
  9963. if len(project) > 0 {
  9964. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9965. }
  9966. }
  9967. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9968. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9969. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9970. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9971. if count > 0 {
  9972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9973. return
  9974. }
  9975. }
  9976. var new_sch models.Schedule
  9977. new_sch = sch
  9978. new_sch.BedId = sch_two.BedId
  9979. new_sch.ScheduleDate = sch_two.ScheduleDate
  9980. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9981. new_sch.PartitionId = sch_two.PartitionId
  9982. new_sch.ScheduleType = sch_two.ScheduleType
  9983. new_sch.ID = 0
  9984. //删除原来的排班
  9985. err := service.SaveSchTwo(sch, sch_two)
  9986. //生成新的排班
  9987. if err == nil {
  9988. err2 := service.SaveSch(&new_sch)
  9989. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9990. if order.ID > 0 {
  9991. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9992. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9993. redis := service.RedisClient()
  9994. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9995. redis.Set(key, "", time.Second)
  9996. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9997. //清空key 值
  9998. redis.Set(keyOne, "", time.Second)
  9999. }
  10000. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10001. if orderOne.ID > 0 {
  10002. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10003. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10004. redis := service.RedisClient()
  10005. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10006. redis.Set(key, "", time.Second)
  10007. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10008. //清空key 值
  10009. redis.Set(keyOne, "", time.Second)
  10010. }
  10011. if err2 == nil {
  10012. //去除当天患者排班中重复数据,保留最后一条数据
  10013. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10014. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10015. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10016. c.ServeSuccessJSON(map[string]interface{}{
  10017. "msg": "覆盖成功",
  10018. "new_sch": new_sch,
  10019. })
  10020. } else {
  10021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10022. return
  10023. }
  10024. } else {
  10025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10026. return
  10027. }
  10028. }
  10029. func (c *DialysisAPIController) BatchCheckAdvice() {
  10030. patient_id, _ := c.GetInt64("patient_id")
  10031. advice_date, _ := c.GetInt64("advice_date")
  10032. org_id := c.GetMobileAdminUserInfo().Org.Id
  10033. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10034. //查询是his系统还是血透系统
  10035. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10036. //his客户
  10037. if configs.IsOpen == 1 {
  10038. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10039. for _, item := range adviceList {
  10040. service.BatchCheckHisAdvice(item.ID, creater)
  10041. }
  10042. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10043. for _, item := range projectList {
  10044. service.BatchCheckProject(item.ID, creater)
  10045. }
  10046. c.ServeSuccessJSON(map[string]interface{}{
  10047. "adviceList": adviceList,
  10048. "projectList": projectList,
  10049. })
  10050. }
  10051. if configs.IsOpen != 1 {
  10052. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10053. for _, item := range adviceList {
  10054. service.BatchAdviceList(item.ID, creater)
  10055. }
  10056. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10057. for _, item := range projectList {
  10058. service.BatchCheckProject(item.ID, creater)
  10059. }
  10060. c.ServeSuccessJSON(map[string]interface{}{
  10061. "adviceList": adviceList,
  10062. "projectList": projectList,
  10063. })
  10064. }
  10065. return
  10066. }
  10067. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10068. org_id := c.GetMobileAdminUserInfo().Org.Id
  10069. drugList, _ := service.GetAllDrugList(org_id)
  10070. c.ServeSuccessJSON(map[string]interface{}{
  10071. "drugList": drugList,
  10072. })
  10073. }
  10074. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10075. org_id := c.GetMobileAdminUserInfo().Org.Id
  10076. dataBody := make(map[string]interface{}, 0)
  10077. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10078. if err != nil {
  10079. utils.ErrorLog(err.Error())
  10080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10081. return
  10082. }
  10083. timeLayout := "2006-01-02"
  10084. loc, _ := time.LoadLocation("Local")
  10085. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10086. utils.ErrorLog("advice_type")
  10087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10088. return
  10089. }
  10090. adviceType := int64(dataBody["advice_type"].(float64))
  10091. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10092. utils.ErrorLog("start_time")
  10093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10094. return
  10095. }
  10096. startTime2, _ := dataBody["start_time"].(string)
  10097. time_arr := strings.Split(startTime2, " ")
  10098. if len(time_arr) > 0 {
  10099. startTime2 = time_arr[0]
  10100. }
  10101. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10102. utils.ErrorLog("advice_date")
  10103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10104. return
  10105. }
  10106. advice_date, _ := dataBody["advice_date"].(string)
  10107. var advicedateunix int64
  10108. if len(advice_date) > 0 {
  10109. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10110. if err != nil {
  10111. fmt.Println(err)
  10112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10113. return
  10114. }
  10115. advicedateunix = theTime.Unix()
  10116. }
  10117. adviceDate := startTime2
  10118. if len(adviceDate) == 0 {
  10119. utils.ErrorLog("len(adviceDate) == 0")
  10120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10121. return
  10122. }
  10123. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10124. if err != nil {
  10125. utils.ErrorLog(err.Error())
  10126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10127. return
  10128. }
  10129. AdviceDate := advicedateunix
  10130. RecordDate := advicedateunix
  10131. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10132. utils.ErrorLog("start_time")
  10133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10134. return
  10135. }
  10136. startTime, _ := dataBody["start_time"].(string)
  10137. if len(startTime) == 0 {
  10138. utils.ErrorLog("len(start_time) == 0")
  10139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10140. return
  10141. }
  10142. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10143. if err != nil {
  10144. utils.ErrorLog(err.Error())
  10145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10146. return
  10147. }
  10148. StartTime := theTime.Unix()
  10149. advice_name, _ := dataBody["advice_name"].(string)
  10150. advice_desc, _ := dataBody["advice_desc"].(string)
  10151. delivery_way, _ := dataBody["delivery_way"].(string)
  10152. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10153. frequency_type := int64(dataBody["frequency_type"].(float64))
  10154. frequency_week, _ := dataBody["frequency_week"].(string)
  10155. prescribing_number := dataBody["prescribing_number"].(float64)
  10156. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10157. remark := dataBody["remark"].(string)
  10158. single_dose := dataBody["single_dose"].(float64)
  10159. single_dose_unit := dataBody["single_dose_unit"].(string)
  10160. patient_id := int64(dataBody["patient_id"].(float64))
  10161. day_count := int64(dataBody["day_count"].(float64))
  10162. groupNo := int64(dataBody["group_no"].(float64))
  10163. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10164. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10165. if groupNo <= 0 {
  10166. group := service.GetMaxAdviceGroupID(org_id)
  10167. groupNo = group + 1
  10168. }
  10169. var template_id = ""
  10170. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10171. template_id = "M" + adviceLastId
  10172. advice := models.DoctorAdvice{
  10173. UserOrgId: org_id,
  10174. PatientId: patient_id,
  10175. AdviceType: adviceType,
  10176. AdviceDate: AdviceDate,
  10177. StartTime: StartTime,
  10178. AdviceName: advice_name,
  10179. AdviceDesc: advice_desc,
  10180. ReminderDate: 0,
  10181. SingleDose: single_dose,
  10182. SingleDoseUnit: single_dose_unit,
  10183. DrugSpec: 0,
  10184. DrugSpecUnit: "",
  10185. PrescribingNumber: prescribing_number,
  10186. PrescribingNumberUnit: prescribing_number_unit,
  10187. DeliveryWay: delivery_way,
  10188. ExecutionFrequency: execution_frequency,
  10189. AdviceDoctor: advice_doctor,
  10190. Status: 1,
  10191. CreatedTime: time.Now().Unix(),
  10192. UpdatedTime: 0,
  10193. AdviceAffirm: "",
  10194. Remark: remark,
  10195. StopTime: 0,
  10196. StopReason: "",
  10197. StopDoctor: 0,
  10198. StopState: 0,
  10199. ParentId: 0,
  10200. ExecutionTime: 0,
  10201. ExecutionStaff: 0,
  10202. ExecutionState: 0,
  10203. Checker: 0,
  10204. RecordDate: RecordDate,
  10205. DialysisOrderId: 0,
  10206. CheckTime: 0,
  10207. CheckState: 0,
  10208. AdviceId: 0,
  10209. RemindType: 0,
  10210. FrequencyType: frequency_type,
  10211. DayCount: day_count,
  10212. WeekDay: frequency_week,
  10213. ChildDoctorAdvice: nil,
  10214. TemplateId: template_id,
  10215. Modifier: 0,
  10216. IsCheck: 0,
  10217. Way: 0,
  10218. DrugId: 0,
  10219. DrugNameId: 0,
  10220. IsMedicine: 0,
  10221. PushStartTime: 0,
  10222. IsSettle: 0,
  10223. IsPrescription: 0,
  10224. GroupNo: groupNo,
  10225. }
  10226. service.CreateMobileAdivce(advice)
  10227. c.ServeSuccessJSON(map[string]interface{}{
  10228. "msg": "保存成功!",
  10229. })
  10230. }
  10231. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10232. patient_id, _ := c.GetInt64("patient_id")
  10233. org_id := c.GetMobileAdminUserInfo().Org.Id
  10234. app_id := c.GetMobileAdminUserInfo().App.Id
  10235. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10236. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10237. c.ServeSuccessJSON(map[string]interface{}{
  10238. "adviceList": adviceList,
  10239. "adminRoles": adminRoles,
  10240. })
  10241. }
  10242. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10243. org_id := c.GetMobileAdminUserInfo().Org.Id
  10244. dataBody := make(map[string]interface{}, 0)
  10245. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10246. if err != nil {
  10247. utils.ErrorLog(err.Error())
  10248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10249. return
  10250. }
  10251. timeLayout := "2006-01-02"
  10252. loc, _ := time.LoadLocation("Local")
  10253. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10254. utils.ErrorLog("start_time")
  10255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10256. return
  10257. }
  10258. startTime2, _ := dataBody["start_time"].(string)
  10259. time_arr := strings.Split(startTime2, " ")
  10260. if len(time_arr) > 0 {
  10261. startTime2 = time_arr[0]
  10262. }
  10263. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10264. utils.ErrorLog("advice_date")
  10265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10266. return
  10267. }
  10268. advice_date, _ := dataBody["advice_date"].(string)
  10269. var advicedateunix int64
  10270. if len(advice_date) > 0 {
  10271. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10272. if err != nil {
  10273. fmt.Println(err)
  10274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10275. return
  10276. }
  10277. advicedateunix = theTime.Unix()
  10278. }
  10279. adviceDate := startTime2
  10280. if len(adviceDate) == 0 {
  10281. utils.ErrorLog("len(adviceDate) == 0")
  10282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10283. return
  10284. }
  10285. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10286. if err != nil {
  10287. utils.ErrorLog(err.Error())
  10288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10289. return
  10290. }
  10291. AdviceDate := advicedateunix
  10292. RecordDate := advicedateunix
  10293. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10294. utils.ErrorLog("start_time")
  10295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10296. return
  10297. }
  10298. startTime, _ := dataBody["start_time"].(string)
  10299. if len(startTime) == 0 {
  10300. utils.ErrorLog("len(start_time) == 0")
  10301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10302. return
  10303. }
  10304. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10305. if err != nil {
  10306. utils.ErrorLog(err.Error())
  10307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10308. return
  10309. }
  10310. StartTime := theTime.Unix()
  10311. advice_name, _ := dataBody["advice_name"].(string)
  10312. advice_desc, _ := dataBody["advice_desc"].(string)
  10313. delivery_way, _ := dataBody["delivery_way"].(string)
  10314. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10315. prescribing_number := dataBody["prescribing_number"].(float64)
  10316. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10317. remark := dataBody["remark"].(string)
  10318. single_dose := dataBody["single_dose"].(float64)
  10319. single_dose_unit := dataBody["single_dose_unit"].(string)
  10320. patient_id := int64(dataBody["patient_id"].(float64))
  10321. groupNo := int64(dataBody["group_no"].(float64))
  10322. parent_id := int64(dataBody["parent_id"].(float64))
  10323. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10324. advice := models.XtDoctorAdviceOne{
  10325. UserOrgId: org_id,
  10326. PatientId: patient_id,
  10327. AdviceType: 1,
  10328. AdviceDate: AdviceDate,
  10329. StartTime: StartTime,
  10330. AdviceName: advice_name,
  10331. AdviceDesc: advice_desc,
  10332. ReminderDate: 0,
  10333. SingleDose: single_dose,
  10334. SingleDoseUnit: single_dose_unit,
  10335. PrescribingNumber: prescribing_number,
  10336. PrescribingNumberUnit: prescribing_number_unit,
  10337. DeliveryWay: delivery_way,
  10338. ExecutionFrequency: execution_frequency,
  10339. AdviceDoctor: advice_doctor,
  10340. Status: 1,
  10341. CreatedTime: time.Now().Unix(),
  10342. UpdatedTime: time.Now().Unix(),
  10343. AdviceAffirm: "",
  10344. Remark: remark,
  10345. StopTime: 0,
  10346. StopReason: "",
  10347. StopDoctor: 0,
  10348. StopState: 0,
  10349. ParentId: parent_id,
  10350. ExecutionTime: 0,
  10351. ExecutionStaff: 0,
  10352. ExecutionState: 0,
  10353. Checker: 0,
  10354. RecordDate: RecordDate,
  10355. DialysisOrderId: 0,
  10356. CheckTime: 0,
  10357. CheckState: 0,
  10358. DrugSpec: 0,
  10359. DrugSpecUnit: "",
  10360. Groupno: groupNo,
  10361. RemindType: 0,
  10362. FrequencyType: 0,
  10363. DayCount: 0,
  10364. WeekDay: "",
  10365. TemplateId: "",
  10366. Modifier: 0,
  10367. }
  10368. service.CreateMobileAdivceOne(advice)
  10369. c.ServeSuccessJSON(map[string]interface{}{
  10370. "msg": "保存成功!",
  10371. })
  10372. }
  10373. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10374. id, _ := c.GetInt64("id")
  10375. service.DeleteSelfAdviceSubAdvice(id)
  10376. c.ServeSuccessJSON(map[string]interface{}{
  10377. "msg": "保存成功!",
  10378. })
  10379. }
  10380. func (c *DialysisAPIController) GetEditAdviceAction() {
  10381. id, _ := c.GetInt64("id")
  10382. org_id := c.GetMobileAdminUserInfo().Org.Id
  10383. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10384. drugList, _ := service.GetAllDrugList(org_id)
  10385. c.ServeSuccessJSON(map[string]interface{}{
  10386. "advice": advice,
  10387. "drugList": drugList,
  10388. })
  10389. }
  10390. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10391. dataBody := make(map[string]interface{}, 0)
  10392. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10393. if err != nil {
  10394. utils.ErrorLog(err.Error())
  10395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10396. return
  10397. }
  10398. timeLayout := "2006-01-02"
  10399. loc, _ := time.LoadLocation("Local")
  10400. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10401. utils.ErrorLog("start_time")
  10402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10403. return
  10404. }
  10405. startTime2, _ := dataBody["start_time"].(string)
  10406. time_arr := strings.Split(startTime2, " ")
  10407. if len(time_arr) > 0 {
  10408. startTime2 = time_arr[0]
  10409. }
  10410. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10411. utils.ErrorLog("advice_date")
  10412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10413. return
  10414. }
  10415. advice_date, _ := dataBody["advice_date"].(string)
  10416. var advicedateunix int64
  10417. if len(advice_date) > 0 {
  10418. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10419. if err != nil {
  10420. fmt.Println(err)
  10421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10422. return
  10423. }
  10424. advicedateunix = theTime.Unix()
  10425. }
  10426. adviceDate := startTime2
  10427. if len(adviceDate) == 0 {
  10428. utils.ErrorLog("len(adviceDate) == 0")
  10429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10430. return
  10431. }
  10432. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10433. if err != nil {
  10434. utils.ErrorLog(err.Error())
  10435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10436. return
  10437. }
  10438. AdviceDate := advicedateunix
  10439. RecordDate := advicedateunix
  10440. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10441. utils.ErrorLog("start_time")
  10442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10443. return
  10444. }
  10445. startTime, _ := dataBody["start_time"].(string)
  10446. if len(startTime) == 0 {
  10447. utils.ErrorLog("len(start_time) == 0")
  10448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10449. return
  10450. }
  10451. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10452. if err != nil {
  10453. utils.ErrorLog(err.Error())
  10454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10455. return
  10456. }
  10457. StartTime := theTime.Unix()
  10458. advice_name, _ := dataBody["advice_name"].(string)
  10459. advice_desc, _ := dataBody["advice_desc"].(string)
  10460. delivery_way, _ := dataBody["delivery_way"].(string)
  10461. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10462. prescribing_number := dataBody["prescribing_number"].(float64)
  10463. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10464. remark := dataBody["remark"].(string)
  10465. single_dose := dataBody["single_dose"].(float64)
  10466. single_dose_unit := dataBody["single_dose_unit"].(string)
  10467. id := int64(dataBody["id"].(float64))
  10468. frequency_type := int64(dataBody["frequency_type"].(float64))
  10469. frequency_week, _ := dataBody["frequency_week"].(string)
  10470. day_count := int64(dataBody["day_count"].(float64))
  10471. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10472. advice := models.XtDoctorAdviceOne{
  10473. AdviceDate: AdviceDate,
  10474. StartTime: StartTime,
  10475. AdviceName: advice_name,
  10476. AdviceDesc: advice_desc,
  10477. SingleDose: single_dose,
  10478. SingleDoseUnit: single_dose_unit,
  10479. PrescribingNumber: prescribing_number,
  10480. PrescribingNumberUnit: prescribing_number_unit,
  10481. DeliveryWay: delivery_way,
  10482. ExecutionFrequency: execution_frequency,
  10483. AdviceDoctor: advice_doctor,
  10484. Remark: remark,
  10485. RecordDate: RecordDate,
  10486. FrequencyType: frequency_type,
  10487. DayCount: day_count,
  10488. WeekDay: frequency_week,
  10489. }
  10490. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10491. c.ServeSuccessJSON(map[string]interface{}{
  10492. "advice": advice,
  10493. })
  10494. }
  10495. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10496. dataBody := make(map[string]interface{}, 0)
  10497. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10498. if err != nil {
  10499. utils.ErrorLog(err.Error())
  10500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10501. return
  10502. }
  10503. timeLayout := "2006-01-02"
  10504. loc, _ := time.LoadLocation("Local")
  10505. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10506. utils.ErrorLog("start_time")
  10507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10508. return
  10509. }
  10510. startTime2, _ := dataBody["start_time"].(string)
  10511. time_arr := strings.Split(startTime2, " ")
  10512. if len(time_arr) > 0 {
  10513. startTime2 = time_arr[0]
  10514. }
  10515. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10516. utils.ErrorLog("advice_date")
  10517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10518. return
  10519. }
  10520. advice_date, _ := dataBody["advice_date"].(string)
  10521. var advicedateunix int64
  10522. if len(advice_date) > 0 {
  10523. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10524. if err != nil {
  10525. fmt.Println(err)
  10526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10527. return
  10528. }
  10529. advicedateunix = theTime.Unix()
  10530. }
  10531. adviceDate := startTime2
  10532. if len(adviceDate) == 0 {
  10533. utils.ErrorLog("len(adviceDate) == 0")
  10534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10535. return
  10536. }
  10537. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10538. if err != nil {
  10539. utils.ErrorLog(err.Error())
  10540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10541. return
  10542. }
  10543. AdviceDate := advicedateunix
  10544. RecordDate := advicedateunix
  10545. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10546. utils.ErrorLog("start_time")
  10547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10548. return
  10549. }
  10550. startTime, _ := dataBody["start_time"].(string)
  10551. if len(startTime) == 0 {
  10552. utils.ErrorLog("len(start_time) == 0")
  10553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10554. return
  10555. }
  10556. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10557. if err != nil {
  10558. utils.ErrorLog(err.Error())
  10559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10560. return
  10561. }
  10562. StartTime := theTime.Unix()
  10563. advice_name, _ := dataBody["advice_name"].(string)
  10564. advice_desc, _ := dataBody["advice_desc"].(string)
  10565. delivery_way, _ := dataBody["delivery_way"].(string)
  10566. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10567. prescribing_number := dataBody["prescribing_number"].(float64)
  10568. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10569. remark := dataBody["remark"].(string)
  10570. single_dose := dataBody["single_dose"].(float64)
  10571. single_dose_unit := dataBody["single_dose_unit"].(string)
  10572. id := int64(dataBody["id"].(float64))
  10573. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10574. advice := models.XtDoctorAdviceOne{
  10575. AdviceDate: AdviceDate,
  10576. StartTime: StartTime,
  10577. AdviceName: advice_name,
  10578. AdviceDesc: advice_desc,
  10579. SingleDose: single_dose,
  10580. SingleDoseUnit: single_dose_unit,
  10581. PrescribingNumber: prescribing_number,
  10582. PrescribingNumberUnit: prescribing_number_unit,
  10583. DeliveryWay: delivery_way,
  10584. ExecutionFrequency: execution_frequency,
  10585. AdviceDoctor: advice_doctor,
  10586. Remark: remark,
  10587. RecordDate: RecordDate,
  10588. }
  10589. service.UpdateMobileDoctorAdviceById(id, advice)
  10590. c.ServeSuccessJSON(map[string]interface{}{
  10591. "advice": advice,
  10592. })
  10593. }
  10594. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10595. dataBody := make(map[string]interface{}, 0)
  10596. timeLayout := "2006-01-02"
  10597. loc, _ := time.LoadLocation("Local")
  10598. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10599. if err != nil {
  10600. utils.ErrorLog(err.Error())
  10601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10602. return
  10603. }
  10604. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10605. utils.ErrorLog("start_time")
  10606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10607. return
  10608. }
  10609. startTime2, _ := dataBody["start_time"].(string)
  10610. time_arr := strings.Split(startTime2, " ")
  10611. if len(time_arr) > 0 {
  10612. startTime2 = time_arr[0]
  10613. }
  10614. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10615. utils.ErrorLog("advice_date")
  10616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10617. return
  10618. }
  10619. advice_date, _ := dataBody["advice_date"].(string)
  10620. var advicedateunix int64
  10621. if len(advice_date) > 0 {
  10622. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10623. if err != nil {
  10624. fmt.Println(err)
  10625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10626. return
  10627. }
  10628. advicedateunix = theTime.Unix()
  10629. }
  10630. adviceDate := startTime2
  10631. if len(adviceDate) == 0 {
  10632. utils.ErrorLog("len(adviceDate) == 0")
  10633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10634. return
  10635. }
  10636. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10637. if err != nil {
  10638. utils.ErrorLog(err.Error())
  10639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10640. return
  10641. }
  10642. RecordDate := advicedateunix
  10643. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10644. utils.ErrorLog("start_time")
  10645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10646. return
  10647. }
  10648. startTime, _ := dataBody["start_time"].(string)
  10649. if len(startTime) == 0 {
  10650. utils.ErrorLog("len(start_time) == 0")
  10651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10652. return
  10653. }
  10654. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10655. if err != nil {
  10656. utils.ErrorLog(err.Error())
  10657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10658. return
  10659. }
  10660. StartTime := theTime.Unix()
  10661. patient_id := int64(dataBody["patient_id"].(float64))
  10662. group_no := int64(dataBody["group_no"].(float64))
  10663. org_id := c.GetMobileAdminUserInfo().Org.Id
  10664. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10665. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10666. utils.ErrorLog("advices")
  10667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10668. return
  10669. }
  10670. adviceNames := dataBody["advices"].([]interface{})
  10671. var advices []*models.GroupAdvice
  10672. for _, adviceNameMap := range adviceNames {
  10673. var advice models.GroupAdvice
  10674. adviceNameM := adviceNameMap.(map[string]interface{})
  10675. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10676. utils.ErrorLog("advice_name")
  10677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10678. return
  10679. }
  10680. adviceName, _ := adviceNameM["advice_name"].(string)
  10681. if len(adviceName) == 0 {
  10682. utils.ErrorLog("len(advice_name) == 0")
  10683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10684. return
  10685. }
  10686. advice.AdviceName = adviceName
  10687. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10688. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10689. advice.DrugSpec = drugSpec
  10690. }
  10691. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10692. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10693. advice.AdviceDesc = adviceDesc
  10694. }
  10695. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10696. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10697. advice.DrugSpecUnit = drugSpecUnit
  10698. }
  10699. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10700. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10701. advice.SingleDose = singleDose
  10702. }
  10703. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10704. singleDose := adviceNameM["single_dose"].(float64)
  10705. advice.SingleDose = singleDose
  10706. }
  10707. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10708. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10709. advice.SingleDoseUnit = singleDoseUnit
  10710. }
  10711. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10712. tmp := adviceNameM["single_dose_unit"].(float64)
  10713. singleDoseUnit := service.TypeConversion(tmp)
  10714. advice.SingleDoseUnit = singleDoseUnit
  10715. }
  10716. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10717. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10718. advice.PrescribingNumber = prescribingNumber
  10719. }
  10720. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10721. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10722. advice.PrescribingNumber = prescribingNumber
  10723. }
  10724. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10725. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10726. advice.PrescribingNumberUnit = prescribingNumberUnit
  10727. }
  10728. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10729. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10730. advice.DeliveryWay = deliveryWay
  10731. }
  10732. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10733. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10734. advice.ExecutionFrequency = executionFrequency
  10735. }
  10736. remark, _ := adviceNameM["remark"].(string)
  10737. advice.Remark = remark
  10738. advice.AdviceType = 1
  10739. advice.StartTime = StartTime
  10740. advice.RecordDate = RecordDate
  10741. advice.PatientId = patient_id
  10742. advice.UserOrgId = org_id
  10743. advice.AdviceDoctor = advice_doctor
  10744. advices = append(advices, &advice)
  10745. }
  10746. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10747. c.ServeSuccessJSON(map[string]interface{}{
  10748. "advice": newAdvices,
  10749. })
  10750. }
  10751. func (c *DialysisAPIController) StopLongAdvice() {
  10752. stop_time := c.GetString("execution_time")
  10753. id, _ := c.GetInt64("id")
  10754. if len(stop_time) <= 0 {
  10755. utils.ErrorLog("stop_time")
  10756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10757. return
  10758. }
  10759. timeLayout2 := "2006-01-02 15:04:05"
  10760. loc, _ := time.LoadLocation("Local")
  10761. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  10762. if errs != nil {
  10763. utils.ErrorLog(errs.Error())
  10764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10765. return
  10766. }
  10767. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  10768. c.ServeSuccessJSON(map[string]interface{}{
  10769. "advice": advice,
  10770. })
  10771. }