1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362 |
- package mobile_api_controllers
-
- import (
- "encoding/json"
- "errors"
- "fmt"
- "math"
- "net/http"
- "net/url"
- "reflect"
- "strconv"
- "strings"
- "time"
-
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- )
-
- // type DialysisTestAPIController struct {
- // MobileBaseAPIController
- // }
-
- // [get]/m/api/test
- // func (this *DialysisTestAPIController) Test() {
- // orgID := int64(3907)
-
- // now := time.Now()
- // nextWeek := now.AddDate(0, 0, 7)
- // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
- // nextTwoWeek := now.AddDate(0, 0, 14)
- // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
- // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
- // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
-
- // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
-
- // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
- // if exchangeErr != nil {
- // this.ErrorLog("%v", exchangeErr)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
-
- // this.ServeSuccessJSON(map[string]interface{}{
- // // "now": now,
- // // "next_week": nextWeek,f
- // // "next_week_mon": nextWeekMon,
- // // "next_week_sun": nextWeekSun,
- // // "next_two_week_mon": nextTwoWeekMon,
- // // "next_two_week_sun": nextTwoWeekSun,
- // "next_week_schs": nextWeekSchs,
- // "next_two_week_schs": nextTwoWeekSchs,
- // })
- // }
-
- type DialysisAPIController struct {
- MobileBaseAPIAuthController
- }
-
- // /m/api/scheduals [get]
- // @param type:int
- // @param date:string
- func (this *DialysisAPIController) Scheduals() {
- schedualType, _ := this.GetInt64("type")
- schedualDate := this.GetString("date")
-
- if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
- schedualType = 0
- }
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
- if parseDateErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminInfo := this.GetMobileAdminUserInfo()
- orgID := adminInfo.Org.Id
-
- redis := service.RedisClient()
- defer redis.Close()
-
- key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
- redis.Set(key, "", time.Second)
- scheduals_json_str, _ := redis.Get(key).Result()
-
- patients, _ := service.GetAllPatientListSix(orgID)
-
- if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
-
- for _, item := range scheduals {
- order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
- item.DialysisLastOrder = order
-
- solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
- item.DialysisSolution = solution
- }
-
- if err != nil {
- this.ErrorLog("获取排班信息失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- } else {
- if len(scheduals) > 0 {
- devices, _ := service.GetAllDevicetByListSix(orgID)
- advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
- prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
- assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
- dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
- treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
- AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
- dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
-
- hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
-
- inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
-
- //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
- for key, item := range scheduals {
-
- for _, infor := range inforMation {
- if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
- scheduals[key].NewDeviceInformation = infor
- break
- }
- }
-
- // 获取患者信息
- for _, patient := range patients {
- if item.PatientId == patient.ID {
- scheduals[key].SchedualPatient = patient
- break
- }
- }
- // 床位信息
- for _, device := range devices {
- if item.BedId == device.ID {
- scheduals[key].DeviceNumber = device
- break
- }
- }
-
- // 医嘱信息
- scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
- for _, advice := range advices {
- if item.PatientId == advice.PatientId {
- scheduals[key].Advices = append(scheduals[key].Advices, advice)
- }
- }
-
- // 医嘱信息
- scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
- for _, hisAdvice := range hisAdvices {
- if item.PatientId == hisAdvice.PatientId {
- scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
- }
- }
-
- // 医嘱信息
- for _, prescription := range prescriptions {
- if item.PatientId == prescription.PatientId {
- scheduals[key].Prescription = prescription
- break
- }
- }
-
- // 透前评估
- for _, assessmentBefore := range assessmentBefores {
- if item.PatientId == assessmentBefore.PatientId {
- scheduals[key].AssessmentBeforeDislysis = assessmentBefore
- break
- }
- }
-
- // 透析上下机
- for _, dialysisOrder := range dialysisOrders {
- if item.PatientId == dialysisOrder.PatientId {
- scheduals[key].DialysisOrder = dialysisOrder
- break
- }
- }
-
- // 治疗小节
- for _, afterDislysis := range AssessmentAfterDislysis {
- if item.PatientId == afterDislysis.PatientId {
- scheduals[key].AssessmentAfterDislysis = afterDislysis
- break
- }
- }
-
- // 透后评估
- for _, treatmentSummary := range treatmentSummarys {
- if item.PatientId == treatmentSummary.PatientId {
- scheduals[key].TreatmentSummary = treatmentSummary
- break
- }
- }
-
- for _, check := range dobulecheck {
- if item.PatientId == check.PatientId {
- scheduals[key].DoubleCheck = check
- break
- }
- }
-
- //// 监测
- //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
- //for _, moni := range monitor {
- // if item.PatientId == moni.PatientId {
- // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
- // }
- //}
- }
- //缓存数据
- scheduals_json, err := json.Marshal(&scheduals)
- if err == nil {
- redis.Set(key, scheduals_json, time.Second*60)
- }
- }
-
- //获取今日所有的处方开的耗材
- _, configs := service.FindXTHisProjectByOrgId(orgID)
- project := make([]*models.HisPrescriptionProjectTwo, 0)
-
- if configs.ID > 0 && configs.IsOpen == 1 {
- project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
- }
-
- //list, _ := service.GetZoneCountList(orgID, date.Unix())
-
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduals": scheduals,
- "project": project,
- })
- }
-
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- var dat []map[string]interface{}
-
- if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
-
- } else {
-
- }
- //获取今日所有的处方开的耗材
- _, configs := service.FindXTHisProjectByOrgId(orgID)
- project := make([]*models.HisPrescriptionProjectTwo, 0)
-
- if configs.ID > 0 && configs.IsOpen == 1 {
- project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduals": dat,
- "redis": "true",
- "date": schedualDate,
- "project": project,
- })
-
- }
-
- }
-
- // /m/api/waiting_scheduals [get]
- // @param date:string
- func (this *DialysisAPIController) WaitingScheduals() {
- schedualDate := this.GetString("date")
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
- if parseDateErr != nil && len(schedualDate) != 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminInfo := this.GetMobileAdminUserInfo()
- orgID := adminInfo.Org.Id
- redis := service.RedisClient()
- defer redis.Close()
-
- // cur_date := time.Now().Format("2006-01-02")
- key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
-
- wait_scheduals, _ := redis.Get(key).Result()
-
- if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
- if err != nil {
- this.ErrorLog("获取排班信息失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- } else {
- returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
- for _, s := range scheduals {
- returnScheduals = append(returnScheduals, s)
- }
-
- if len(returnScheduals) > 0 {
- //缓存数据
- wait_scheduals_json, err := json.Marshal(scheduals)
- if err == nil {
- redis.Set(key, wait_scheduals_json, time.Second*30)
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduals": scheduals,
- })
- }
-
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- var dat []map[string]interface{}
- if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
-
- } else {
-
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduals": dat,
- "redis": "true",
- "date": schedualDate,
- })
- }
-
- }
-
- //else{
- // fmt.Println("33333333")
- //
- // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
- // if err != nil {
- // this.ErrorLog("获取排班信息失败:%v", err)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // } else {
- // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
- // for _, s := range scheduals {
- //
- // returnScheduals = append(returnScheduals, s)
- // }
- //
- // this.ServeSuccessJSON(map[string]interface{}{
- // "scheduals": returnScheduals,
- // })
- // }
- //
- // }
-
- //if err == nil{
- //
- //
- //
- //
- //
- //}else{
-
- //}
-
- // /m/api/dialysis/record [get]
- // @param patient_id:int
- // @param date:string (yyyy-MM-dd)
- func (this *DialysisAPIController) DialysisRecord() {
- patientID, _ := this.GetInt64("patient_id")
- recordDateStr := this.GetString("date")
- if patientID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminInfo := this.GetMobileAdminUserInfo()
-
- ch := make(chan struct{})
- count := 24 // count 表示活动的协程个数
- var patient models.Patients
- var receiverTreatmentAccess *models.ReceiveTreatmentAsses
- var predialysisEvaluation *models.PredialysisEvaluation
- var lastPredialysisEvaluation *models.PredialysisEvaluation
- var doctorAdvices []*models.DoctorAdvice
- var dialysisOrder *models.DialysisOrder
- var doubleCheck *models.DoubleCheck
- var monitorRecords []*models.MonitoringRecord
- var lastMonitorRecord *models.MonitoringRecord
- var assessmentAfterDislysis *models.AssessmentAfterDislysis
- var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
- var treatmentSummary *models.TreatmentSummary
- var dialysisPrescribe *models.DialysisPrescription
- var dialysisSolution *models.DialysisSolution
- var lastDialysisPrescribe *models.DialysisPrescription
- var systemDialysisPrescribe *models.SystemPrescription
- var is_project_open_config models.XtHisProjectConfig
- var projects []*models.HisPrescriptionProject
-
- var projectsOne []*models.HisPrescriptionProject
- var stockType []*models.GoodsTypeOne
- var prepare []*models.XtDialysisBeforePrepare
- var lastAssessment models.XtPatientVascularAccess
-
- var lastDryWeightDislysis *models.SgjPatientDryweight
- var gobalConfig models.GobalConfig
- var operators []*models.SgjUserAdminRoles
-
- // 先走redis,没有走数据库
- schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
- go func() {
- patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
-
- ch <- struct{}{}
- }()
-
- go func() {
- receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
-
- ch <- struct{}{}
- }()
-
- go func() {
- dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
-
- ch <- struct{}{}
- }()
-
- go func() {
- doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
-
- ch <- struct{}{}
- }()
-
- go func() {
- lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
- ch <- struct{}{}
- }()
-
- go func() {
- dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
- ch <- struct{}{}
- }()
-
- go func() {
- lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
-
- ch <- struct{}{}
- }()
-
- go func() {
- systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
- ch <- struct{}{}
- }()
-
- go func() {
- // 先走redis,没有走数据库
- _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
- ch <- struct{}{}
- }()
-
- go func() {
- // 先走redis,没有走数据库
- projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- // // 先走redis,没有走数据库
- stockType, _ = service.GetStockType(adminInfo.Org.Id)
- ch <- struct{}{}
- }()
-
- go func() {
- // 先走redis,没有走数据库
- prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
- ch <- struct{}{}
- }()
-
- go func() {
- // //获取最后一次血管通路
- // 先走redis,没有走数据库
- lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
- ch <- struct{}{}
- }()
-
- go func() {
- // 先走redis,没有走数据库
- lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
- ch <- struct{}{}
- }()
-
- go func() {
- // 先走redis,没有走数据库
- _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
- ch <- struct{}{}
- }()
-
- go func() {
- // 先走redis,没有走数据库
- operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
- ch <- struct{}{}
- }()
-
- for range ch {
- // 每次从ch中接收数据,表明一个活动的协程结束
- count--
- // 当所有活动的协程都结束时,关闭管道
- if count == 0 {
- close(ch)
- }
- }
-
- prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
- _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
-
- _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
-
- projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
-
- temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
-
- prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
-
- var team_projects []*models.HisPrescriptionProject
- //var index int64 = 0
- for _, item := range temp_team_projects {
- //组套里面非检验项目的
- if item.HisProject.CostClassify != 3 {
- projects = append(projects, item)
- }
- //组套里面检验项目的
- if item.HisProject.CostClassify == 3 {
- team_projects = append(team_projects, item)
- }
- }
-
- //针对茂名舒和
- if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
- if len(projects) > 0 {
- for _, item := range projects {
- if item.Type == 2 {
- if item.HisProject.IsShow == 1 {
- projectsOne = append(projectsOne, item)
- }
- }
-
- if item.Type == 3 {
- if item.GoodInfo.IsShow == 1 {
- projectsOne = append(projectsOne, item)
- }
- }
- }
- }
- } else {
- for _, item := range projects {
- projectsOne = append(projectsOne, item)
- }
- }
-
- team_projects = RemoveRepeatedCheckRecod(team_projects)
-
- stockType, _ = service.GetStockType(adminInfo.Org.Id)
-
- prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
-
- prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
- var his_advices []*models.HisDoctorAdviceInfo
-
- var his_advices_one []*models.HisDoctorAdviceInfo
- if is_open_config.IsOpen == 1 {
- // 先走redis,没有走数据库
- his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
- }
- //针对茂名舒和
- if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
- if len(his_advices) > 0 {
- for _, item := range his_advices {
- drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
- if drug.IsShow == 1 {
- his_advices_one = append(his_advices_one, item)
- }
- }
- }
- } else {
- if len(his_advices) > 0 {
- for _, item := range his_advices {
- his_advices_one = append(his_advices_one, item)
- }
- }
- }
-
- is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
-
- if is_advice_open.IsAdviceOpen == 1 {
- his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
- }
-
- lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
- remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
- var remind_lists []models.XtCheckRemind
- if remind_config.ID > 0 && remind_config.IsOpen == 1 {
- remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
- }
-
- lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
-
- lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
-
- dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
-
- lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
-
- firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
-
- returnData := map[string]interface{}{
- "patient": patient,
- "schedual": schedual,
- "prescription": dialysisPrescribe,
- "solution": dialysisSolution,
- "last_prescription": lastDialysisPrescribe,
- "receiver_treatment_access": receiverTreatmentAccess,
- "predialysis_evaluation": predialysisEvaluation,
- "doctor_advices": doctorAdvices,
- "double_check": doubleCheck,
- "assessment_after_dislysis": assessmentAfterDislysis,
- "treatment_summary": treatmentSummary,
- "monitor_records": monitorRecords,
- "dialysis_order": dialysisOrder,
- "operators": operators,
- "last_predialysis_evaluation": lastPredialysisEvaluation,
- "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
- "last_monitor_record": lastMonitorRecord,
- "config": gobalConfig,
- "dry_weight": lastDryWeightDislysis,
- "system_prescription": systemDialysisPrescribe,
- "his_advices": his_advices_one,
- "is_open_config": is_open_config,
- "stockType": stockType,
- "prepare": prepare,
- "lastAssessment": lastAssessment,
- "prescribeOne": prescribeOne,
- "is_project_open_config": is_project_open_config,
- "project": projectsOne,
- "team_projects": team_projects,
- "is_advice_open": is_advice_open,
- "prescription_open": prescriptionConfig.IsOpen,
- "lastOrder": lastOrder,
- "remind_lists": remind_lists,
- "lastDialysisPrescription": lastDialysisPrescription,
- "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
- "dryWeightList": dryWeightList,
- "firstMonitor": firstMonitor,
- "lastMonitor": lastMonitor,
- }
-
- this.ServeSuccessJSON(returnData)
- }
-
- func (c *DialysisAPIController) GetDialysisGlobalConfig() {
- adminInfo := c.GetMobileAdminUserInfo()
-
- adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
- devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
- device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
-
- returnData := map[string]interface{}{
- "admin_users": adminUsers,
- "devices": devices,
- "device_numbers": device_numbers,
- }
- c.ServeSuccessJSON(returnData)
-
- }
-
- func (c *DialysisAPIController) PostAtreatmentInfo() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
- summaryContent := c.GetString("summaryContent")
- changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
- treatNurseId, _ := c.GetInt64("treatNurse", 0)
- checkStaffId, _ := c.GetInt64("checkStaff", 0)
- deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
- treatDoctor, _ := c.GetInt64("treatDoctor", 0)
- nursingRecord := c.GetString("nursing_record")
- fmt.Println("护理记录", nursingRecord)
- specialRecord := c.GetString("special_record")
- fmt.Println("特殊记录", specialRecord)
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- changeMedicalNurseId = adminUserInfo.AdminUser.Id
- checkStaffId = adminUserInfo.AdminUser.Id
- deboardNurseId = adminUserInfo.AdminUser.Id
- treatDoctor = adminUserInfo.AdminUser.Id
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- summary := models.TreatmentSummary{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- AssessmentDate: recordDate.Unix(),
- Mission: propagandaAndEducationContent,
- DialysisSummary: summaryContent,
- SjNurse: changeMedicalNurseId,
- ZlNurse: treatNurseId,
- HdNurse: checkStaffId,
- XjNurse: deboardNurseId,
- ZlDoctor: treatDoctor,
- CreatedTime: time.Now().Unix(),
- Status: 1,
- NursingRecord: nursingRecord,
- SpecialRecord: specialRecord,
- }
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= recordDate.Unix() {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if treatmentSummary.ID == 0 { //新增
- summary.Creater = adminUserInfo.AdminUser.Id
- service.AddSigleSummaryRecord(&summary)
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 10,
- RecordDate: recordDate.Unix(),
- Sourse: 1,
- PatientId: id,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
- redis.Set(keyOne, "", time.Second)
- keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyThree, "", time.Second)
- defer redis.Close()
- c.ServeSuccessJSON(map[string]interface{}{
- "summary": summary,
- })
- } else { //修改
-
- summary.Creater = treatmentSummary.Creater
- summary.CreatedTime = treatmentSummary.CreatedTime
-
- summary.Modifier = adminUserInfo.AdminUser.Id
- summary.ID = treatmentSummary.ID
- service.UpdateSummeRecord(&summary)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
- redis.Set(keyOne, "", time.Second)
- keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyThree, "", time.Second)
- defer redis.Close()
- c.ServeSuccessJSON(map[string]interface{}{
- "summary": summary,
- })
- }
- }
-
- func (c *DialysisAPIController) PostDoubleCheck() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- checkTimeStr := c.GetString("check_time")
- firstCheckTimeStr := c.GetString("first_check_time")
-
- creater, _ := c.GetInt64("creater", 0)
- modifier, _ := c.GetInt64("modifier", 0)
-
- dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
- dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
- vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
- pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
- dialysis_item_desc := c.GetString("dialysis_item_desc")
- dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
- vascular_access_desc := c.GetString("vascular_access_desc")
- pipeline_connection_desc := c.GetString("pipeline_connection_desc")
- collator, _ := c.GetInt64("collator", 0)
- employee_number := c.GetString("employee_number")
- dialyzer_batch_number := c.GetString("dialyzer_batch_number")
- needle_batch_number := c.GetString("needle_batch_number")
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var checkDate int64
-
- if len(checkTimeStr) == 0 {
- checkDate = 0
- } else {
- checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
- checkDate = checkDateUnix.Unix()
-
- }
-
- var firstCheckDate int64
-
- if len(firstCheckTimeStr) == 0 {
- firstCheckDate = 0
- } else {
- firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
- firstCheckDate = firstCheckDateUnix.Unix()
- }
-
- if adminUserInfo.Org.Id == 10644 {
-
- list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
- _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if check.ID == 0 {
- if employee_number != list.JobNumber {
- c.ServeSuccessJSON(map[string]interface{}{
- "doubleCheck": check,
- "msg": "2",
- })
- return
- }
- }
- if check.ID > 0 {
- if employee_number != list.JobNumber {
- c.ServeSuccessJSON(map[string]interface{}{
- "doubleCheck": check,
- "msg": "2",
- })
- return
- }
- }
-
- }
-
- doubleCheck := models.DoubleCheck{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- DialysisItemCheck: dialysis_item_check,
- DialysisParameterCheck: dialysis_parameter_check,
- VascularAccessVerification: vascular_access_verification,
- PipelineConnectionCheck: pipeline_connection_check,
- DialysisItemDesc: dialysis_item_desc,
- DialysisParameterDesc: dialysis_parameter_desc,
- VascularAccessDesc: vascular_access_desc,
- PipelineConnectionDesc: pipeline_connection_desc,
- Collator: collator,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- CheckDate: recordDate.Unix(),
- UpdatedTime: time.Now().Unix(),
- EmployeeNumber: employee_number,
- DialyzerBatchNumber: dialyzer_batch_number,
- NeedleBatchNumber: needle_batch_number,
- }
-
- _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if check.ID == 0 { //新增
- doubleCheck.FirstCheckTime = firstCheckDate
- doubleCheck.CheckTime = checkDate
- doubleCheck.Creater = creater
- doubleCheck.Modifier = modifier
- if adminUserInfo.Org.Id == 10340 {
- order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
- doubleCheck.Creater = order.StartNurse
- }
-
- if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
- //查询未核对的医嘱
- doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
- for _, advice := range doctorList {
- if advice.ExecutionStaff == modifier {
-
- c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
- c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
- return
- }
- }
- }
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= recordDate.Unix() {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- err := service.AddSigleDoubleCheck(&doubleCheck)
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 5,
- RecordDate: recordDate.Unix(),
- Sourse: 1,
- PatientId: id,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
-
- //针对长沙南雅
- if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
- //查询未核对的医嘱
- doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if len(doctorList) > 0 && modifier > 0 {
- for _, advice := range doctorList {
-
- service.UpdateDoctorAdviceList(advice.ID, modifier)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- theTime := time.Now()
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyFour, "", time.Second)
- defer redis.Close()
- }
- }
-
- }
-
- //针对溪康
- if adminUserInfo.Org.Id == 10721 {
-
- adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
- if len(adviceInfoList) > 0 {
- for _, item := range adviceInfoList {
-
- service.UpdateHisAdviceList(item.ID, creater)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- theTime := time.Now()
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyFour, "", time.Second)
- defer redis.Close()
- }
- }
-
- adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
- if len(adviceList) > 0 {
- for _, item := range adviceList {
- service.UpdateAdviceList(item.ID, creater)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- theTime := time.Now()
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyFour, "", time.Second)
- defer redis.Close()
- }
- }
- }
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "doubleCheck": &doubleCheck,
- })
- }
- } else { //修改
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
- if infor.ID > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= recordDate.Unix() {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- doubleCheck.FirstCheckTime = firstCheckDate
- doubleCheck.CheckTime = checkDate
- doubleCheck.Creater = creater
- doubleCheck.Modifier = modifier
- doubleCheck.CreatedTime = check.CreatedTime
- doubleCheck.ID = check.ID
- doubleCheck.EmployeeNumber = employee_number
- doubleCheck.NeedleBatchNumber = needle_batch_number
- doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
-
- if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
- //查询未核对的医嘱
- doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
- for _, advice := range doctorList {
- if advice.ExecutionStaff == modifier {
-
- c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
- c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
- return
- }
- }
- }
-
- //针对溪康
- if adminUserInfo.Org.Id == 10721 {
-
- adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
- if len(adviceInfoList) > 0 {
- for _, item := range adviceInfoList {
-
- service.UpdateHisAdviceList(item.ID, creater)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- theTime := time.Now()
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyFour, "", time.Second)
- defer redis.Close()
- }
- }
-
- adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
- if len(adviceList) > 0 {
- for _, item := range adviceList {
- service.UpdateAdviceList(item.ID, creater)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- theTime := time.Now()
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyFour, "", time.Second)
- defer redis.Close()
- }
- }
- }
-
- err := service.UpdateDoubleCheck(&doubleCheck)
-
- //针对长沙南雅
- if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
- //查询未核对的医嘱
- doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if len(doctorList) > 0 && modifier > 0 {
- for _, advice := range doctorList {
- service.UpdateDoctorAdviceList(advice.ID, modifier)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- theTime := time.Now()
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyFour, "", time.Second)
- defer redis.Close()
- }
- }
-
- }
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- redis.Set(keyOne, "", time.Second)
-
- defer redis.Close()
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "doubleCheck": &doubleCheck,
- "msg": "1",
- })
- }
-
- }
-
- }
- func (c *DialysisAPIController) PostAcceptsAssessment() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- way, _ := c.GetInt64("way", 0)
- consciousness, _ := c.GetInt64("consciousness", 0)
- appetite, _ := c.GetInt64("appetite", 0)
- condition, _ := c.GetInt64("condition", 0)
- posture, _ := c.GetInt64("posture")
- sick_condition, _ := c.GetInt64("sick_condition", 0)
- danger_level, _ := c.GetInt64("danger_level", 0)
- intake, _ := c.GetInt64("intake", 0)
- nutrition, _ := c.GetInt64("nutrition", 0)
- psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
- psychological_assessment_other := c.GetString("psychological_assessment_other")
- score := c.GetString("score")
- sick_condition_other := c.GetString("sick_condition_other")
-
- //precaution, _ := c.GetInt64("precaution", 0)
- precaution := c.GetString("precaution")
- precaution_other := c.GetString("precaution_other")
- psychological_other := c.GetString("psychological_other")
-
- admission_number := c.GetString("admission_number")
- tumble, _ := c.GetInt64("tumble")
- diacrisis := c.GetString("diacrisis")
- his_department := c.GetString("his_department")
- his_bed := c.GetString("his_bed")
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- //now := time.Now()
- //year, month, day := now.Date()
- //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
- //todayTimeStamp := today_time.Unix()
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= recordDate.Unix() {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
-
- if adminUserInfo.Org.Id == 10340 {
- if condition == 1 {
- lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
- if admission_number == "" {
- admission_number = lastAcceptTreatment.AdmissionNumber
- }
- }
- }
-
- receiveTreatmentAsses := models.ReceiveTreatmentAsses{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- RecordDate: recordDate.Unix(),
- Way: way,
- Consciousness: consciousness,
- Appetite: appetite,
- Condition: condition,
- SickCondition: sick_condition,
- DangerLevel: danger_level,
- Intake: intake,
- Nutrition: nutrition,
- PsychologicalAssessment: psychological_assessment,
- PsychologicalAssessmentOther: psychological_assessment_other,
- SickConditionOther: sick_condition_other,
- Posture: posture,
- CreatedTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- Status: 1,
- Score: score,
- Precaution: precaution,
- PrecautionOther: precaution_other,
- PsychologicalOther: psychological_other,
- AdmissionNumber: admission_number,
- Tumble: tumble,
- Diacrisis: diacrisis,
- HisBed: his_bed,
- HisDepartment: his_department,
- }
-
- if receiveTreatment.ID == 0 { //新增
- receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
- err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 2,
- RecordDate: recordDate.Unix(),
- Sourse: 1,
- PatientId: id,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
- redis := service.RedisClient()
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyOne, "", time.Second)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "receiveTreatmentAsses": receiveTreatmentAsses,
- })
- }
-
- } else { //修改
- //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= recordDate.Unix() {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- receiveTreatmentAsses.Creater = receiveTreatment.Creater
- receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
-
- receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
- receiveTreatmentAsses.ID = receiveTreatment.ID
-
- if adminUserInfo.Org.Id == 10340 {
- if condition == 1 {
- lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
- if receiveTreatmentAsses.AdmissionNumber == "" {
- receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
- }
- }
- }
- err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
- redis := service.RedisClient()
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- redis.Set(keyOne, "", time.Second)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "receiveTreatmentAsses": receiveTreatmentAsses,
- })
- }
- }
-
- }
- func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- weightAfter, _ := c.GetFloat("weight_after", 0)
- additionalWeight, _ := c.GetFloat("additional_weight", 0)
- weightReduce, _ := c.GetFloat("weight_loss", 0)
- fmt.Println("weight_loss", weightReduce)
- temperature, _ := c.GetFloat("temperature", 0)
- pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
- breathing_rate := c.GetString("breathing_rate")
- systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
-
- diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
- actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
-
- actual_displacement, _ := c.GetFloat("actual_displacement", 0)
-
- actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
- actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
- cruor := c.GetString("cruor")
- symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
- internalFistula := c.GetString("internal_fistula")
- catheter := c.GetString("catheter")
- complications := c.GetString("complication")
- remark := c.GetString("remark")
- //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
- dialysis_intakes := c.GetString("dialysis_intakes")
- dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
-
- dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
-
- blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
- blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
-
- puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
- puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
- internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
- patientGose, _ := c.GetInt64("patient_gose", 0)
- inpatientDepartment := c.GetString("inpatient_department")
- observationContent := c.GetString("observation_content")
- observationContentOther := c.GetString("observation_content_other")
- dialysis_process, _ := c.GetInt64("dialysis_process", 0)
-
- in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
- in_advance_reason := c.GetString("in_advance_reason")
- hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
- hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
- tremor_noise, _ := c.GetInt64("tremor_noise", 0)
- disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
- disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
-
- arterial_tube, _ := c.GetInt64("arterial_tube", 0)
- intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
- dialyzer, _ := c.GetInt64("dialyzer", 0)
- in_advance_reason_other := c.GetString("in_advance_reason_other")
- is_eat, _ := c.GetInt64("is_eat", 0)
-
- cvc_a, _ := c.GetFloat("cvc_a", 0)
- cvc_v, _ := c.GetFloat("cvc_v", 0)
- channels, _ := c.GetInt64("channel", 0)
- return_blood, _ := c.GetInt64("return_blood", 0)
- rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
- //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
- dialysis_during, _ := c.GetFloat("dialysis_during")
- stroke_volume, _ := c.GetInt64("stroke_volume", 0)
- blood_flow, _ := c.GetInt64("blood_flow", 0)
- //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
- sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
- sealing_fluid_special := c.GetString("sealing_fluid_special")
- dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
- supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
- setting_pressure := c.GetString("setting_pressure")
- supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
- diastolic_pressure := c.GetString("diastolic_pressure")
- other_complication := c.GetString("other_complication")
- ktv := c.GetString("ktv")
- urr := c.GetString("urr")
- hypertenison, _ := c.GetInt64("hypertenison")
- hypopiesia, _ := c.GetInt64("hypopiesia")
- leave_office_method, _ := c.GetInt64("leave_office_method")
- lapse, _ := c.GetInt64("lapse")
- consciousness, _ := c.GetInt64("consciousness")
- fallrisk, _ := c.GetInt64("fallrisk")
- machine_run := c.GetString("machine_run")
- after_urea := c.GetString("after_urea")
- pip_coagulation := c.GetString("pip_coagulation")
- accumulated_blood_volume := c.GetString("accumulated_blood_volume")
- transfusion_volume := c.GetString("transfusion_volume")
- last_after_weight := c.GetString("last_after_weight")
- displace_liqui_value := c.GetString("displace_liqui_value")
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
-
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- fmt.Println("parseDateErr", parseDateErr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //now := time.Now()
- //year, month, day := now.Date()
- //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
- //todayTimeStamp := today_time.Unix()
-
- //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
-
- assessmentAfterDislysis := models.AssessmentAfterDislysis{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- AssessmentDate: recordDate.Unix(),
- Temperature: temperature,
- PulseFrequency: pulse_frequency,
- BreathingRate: breathing_rate,
- SystolicBloodPressure: systolic_blood_pressure,
- DiastolicBloodPressure: diastolic_blood_pressure,
- ActualUltrafiltration: actual_ultrafiltration,
- ActualDisplacement: actual_displacement,
- ActualTreatmentHour: actualtreatHour,
- ActualTreatmentMinute: actualtreatmin,
- WeightAfter: weightAfter,
- AdditionalWeight: additionalWeight,
- WeightLoss: weightReduce,
- Cruor: cruor,
- SymptomAfterDialysis: symptomsAfterDialysi,
- InternalFistula: internalFistula,
- Catheter: catheter,
- Complication: complications,
- DialysisIntakes: dialysateVolume,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- Status: 1,
- Remark: remark,
- BloodAccessPartId: blood_access_part_id,
- BloodAccessPartOperaId: blood_access_part_opera_id,
- DialysisIntakesUnit: dialysis_intakes_unit,
- PuncturePointOozingBlood: puncturePointOozingBlood,
- PuncturePointHaematoma: puncturePointHaematoma,
- InternalFistulaTremorAc: internalFistulaTremorAc,
- PatientGose: patientGose,
- InpatientDepartment: inpatientDepartment,
- ObservationContent: observationContent,
- ObservationContentOther: observationContentOther,
- DialysisProcess: dialysis_process,
- InAdvanceMinute: in_advance_minute,
- InAdvanceReason: in_advance_reason,
- HemostasisMinute: hemostasis_minute,
- HemostasisOpera: hemostasis_opera,
- TremorNoise: tremor_noise,
- DisequilibriumSyndrome: disequilibrium_syndrome,
- DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
- ArterialTube: arterial_tube,
- IntravenousTube: intravenous_tube,
- Dialyzer: dialyzer,
- InAdvanceReasonOther: in_advance_reason_other,
- IsEat: is_eat,
- CvcA: cvc_a,
- CvcV: cvc_v,
- Channel: channels,
- ReturnBlood: return_blood,
- RehydrationVolume: rehydration_volume,
- DialysisDuring: dialysis_during,
- StrokeVolume: stroke_volume,
- BloodFlow: blood_flow,
- SealingFluidDispose: sealing_fluid_dispose,
- SealingFluidSpecial: sealing_fluid_special,
- DosageOfAnticoagulants: dosage_of_anticoagulants,
- SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
- SupineSystolicBloodPressure: supine_systolic_blood_pressure,
- SettingPressure: setting_pressure,
- DiastolicPressure: diastolic_pressure,
- OtherComplication: other_complication,
- Ktv: ktv,
- Urr: urr,
- Hypopiesia: hypopiesia,
- Hypertenison: hypertenison,
- Lapse: lapse,
- LeaveOfficeMethod: leave_office_method,
- Consciousness: consciousness,
- Fallrisk: fallrisk,
- MachineRun: machine_run,
- AfterUrea: after_urea,
- PipCoagulation: pip_coagulation,
- AccumulatedBloodVolume: accumulated_blood_volume,
- TransfusionVolume: transfusion_volume,
- LastAfterWeight: last_after_weight,
- DisplaceLiquiValue: displace_liqui_value,
- }
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
- fmt.Println("recordDate.Unix()", recordDate.Unix())
- if cha_time >= recordDate.Unix() {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if assessmentAfter.ID == 0 { //新增
- if appRole.UserType == 2 || appRole.UserType == 1 {
- assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
- assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
-
- } else {
- assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
-
- }
-
- recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
-
- if assessmentAfterDislysis.UserOrgId != 10340 {
- if assessmentAfterDislysis.WeightAfter == 0 {
- assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
- }
- }
-
- if adminUserInfo.Org.Id == 10693 {
-
- if assessmentAfterDislysis.ActualUltrafiltration == 0 {
-
- lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
-
- UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
-
- assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
-
- }
-
- if assessmentAfterDislysis.SystolicBloodPressure == 0 {
- lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
- systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
- assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
- }
-
- if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
-
- lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
- MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
- assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
- }
-
- if assessmentAfterDislysis.PulseFrequency == 0 {
- lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
- PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
- assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
- }
-
- if assessmentAfterDislysis.ActualDisplacement == 0 {
-
- lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
- DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
- assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
- }
- }
-
- err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
-
- //记录日志
- byterequest, _ := json.Marshal(assessmentAfterDislysis)
- afterDialysisLog := models.XtAssessmentAfterDialysisLog{
- UserOrgId: assessmentAfterDislysis.UserOrgId,
- PatientId: assessmentAfterDislysis.PatientId,
- RecordDate: assessmentAfterDislysis.AssessmentDate,
- Status: 1,
- ErrLog: string(byterequest),
- AdminUserId: adminUserInfo.AdminUser.Id,
- Ctime: 0,
- Mtime: 0,
- Source: "手机端保存透后评估",
- }
- service.CreateAfterDialysisLog(afterDialysisLog)
-
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 9,
- RecordDate: recordDate.Unix(),
- Sourse: 1,
- PatientId: id,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
- redis := service.RedisClient()
- keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyTwo, "", time.Second)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "assessmentAfterDislysis": assessmentAfterDislysis,
- })
- }
- return
- } else { //修改
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
- if cha_time >= recordDate.Unix() {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- if appRole.UserType == 2 || appRole.UserType == 1 {
- assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
- assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
- } else {
- assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
- if assessmentAfterDislysis.Creater == 0 {
- assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
- }
- }
-
- assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
- assessmentAfterDislysis.ID = assessmentAfter.ID
- recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
-
- if assessmentAfterDislysis.UserOrgId != 10340 {
- if assessmentAfterDislysis.WeightAfter == 0 {
- assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
- }
- }
-
- if adminUserInfo.Org.Id == 10693 {
-
- if assessmentAfterDislysis.ActualUltrafiltration == 0 {
-
- lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
-
- UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
-
- assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
-
- }
-
- if assessmentAfterDislysis.SystolicBloodPressure == 0 {
- lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
- systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
- assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
- }
-
- if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
-
- lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
- MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
- assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
- }
-
- if assessmentAfterDislysis.PulseFrequency == 0 {
- lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
- PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
- assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
- }
-
- if assessmentAfterDislysis.ActualDisplacement == 0 {
-
- lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
- DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
- assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
- }
- }
- err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
-
- //记录日志
- byterequest, _ := json.Marshal(assessmentAfterDislysis)
- afterDialysisLog := models.XtAssessmentAfterDialysisLog{
- UserOrgId: assessmentAfterDislysis.UserOrgId,
- PatientId: assessmentAfterDislysis.PatientId,
- RecordDate: assessmentAfterDislysis.AssessmentDate,
- Status: 1,
- ErrLog: string(byterequest),
- AdminUserId: adminUserInfo.AdminUser.Id,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "手机端修改保存透后评估",
- }
- service.CreateAfterDialysisLog(afterDialysisLog)
-
- redis := service.RedisClient()
- keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- redis.Set(keyTwo, "", time.Second)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
- redis.Set(keyOne, "", time.Second)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "assessmentAfterDislysis": assessmentAfterDislysis,
- })
- return
- }
-
- }
-
- return
- }
-
- func (c *DialysisAPIController) PostDialysisPrescription() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
-
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- mode_id, _ := c.GetInt64("mode_id", 0)
- dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
- dialyzer, _ := c.GetInt64("dialyzer", 0)
- perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
- blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
- dewater_amount, _ := c.GetFloat("dewater_amount", 0)
- displace_liqui, _ := c.GetFloat("displace_liqui", 0)
- replacement_total, _ := c.GetFloat("replacement_total", 0)
-
- replacement_way, _ := c.GetInt64("replacement_way", 0)
- anticoagulant, _ := c.GetInt64("anticoagulant", 0)
- anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
- anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
- anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
- anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
- anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
- dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
-
- kalium, _ := c.GetFloat("kalium", 0)
- sodium, _ := c.GetFloat("sodium", 0)
- calcium, _ := c.GetFloat("calcium", 0)
- bicarbonate, _ := c.GetFloat("bicarbonate", 0)
- glucose, _ := c.GetFloat("glucose", 0)
- // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
-
- // dry_weight, _ := c.GetFloat("dry_weight", 0)
- dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
- dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
- conductivity, _ := c.GetFloat("conductivity", 0)
- remark := c.GetString("remark")
- dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
- dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
- targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
- dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
- body_fluid, _ := c.GetInt64("body_fluid", 0)
- special_medicine, _ := c.GetInt64("special_medicine", 0)
- special_medicine_other := c.GetString("special_medicine_other")
- displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
- displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
- blood_access, _ := c.GetInt64("blood_access", 0)
- ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
- body_fluid_other := c.GetString("body_fluid_other")
-
- niprocart, _ := c.GetInt64("niprocart", 0)
- jms, _ := c.GetInt64("jms", 0)
- fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
- fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
- hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
- dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
- filtryzer, _ := c.GetInt64("filtryzer", 0)
- target_ktv, _ := c.GetFloat("target_ktv", 0)
-
- dialyzers, _ := c.GetInt64("dialyzers", 0)
- injector, _ := c.GetInt64("injector", 0)
- bloodlines, _ := c.GetInt64("bloodlines", 0)
- tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
- safe_package, _ := c.GetInt64("package", 0)
- a_liquid, _ := c.GetInt64("a_liquid", 0)
- pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
-
- anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
- anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
- blood := c.GetString("blood")
- dialysis_dialyszers := c.GetString("dialysis_dialyszers")
- dialysis_irrigation := c.GetString("dialysis_irrigation")
- antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
- displace_speed := c.GetString("displace_speed")
- illness, _ := c.GetInt64("illness")
- amylaceum := c.GetString("amylaceum")
- single_time := c.GetString("single_time")
- single_water := c.GetString("single_water")
- replacement_flow := c.GetString("replacement_flow")
-
- plasma_separator := c.GetString("plasma_separator")
- bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
- oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
- oxygen_flow := c.GetString("oxygen_flow")
- oxygen_time := c.GetString("oxygen_time")
-
- hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
- hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
-
- puncture_needle := c.GetString("puncture_needle")
- puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
-
- epo := c.GetString("epo")
- epo_count, _ := c.GetFloat("epo_count", 0)
-
- max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
- admin_user_id, _ := c.GetInt64("admin_user_id")
-
- is_water := c.GetString("is_water")
-
- var is_war int64
- if is_water == "是" {
- is_war = 1
- }
- if is_water == "否" {
- is_war = 2
- }
- if is_water == "请选择" {
- is_war = 0
- }
- drhy_water := c.GetString("drhy_water")
-
- dry_water_hour := c.GetString("dry_water_hour")
-
- water_machine := c.GetString("water_machine")
- add_amount, _ := c.GetFloat("add_amount")
- reduce_amount, _ := c.GetFloat("reduce_amount")
- dialysis_remark := c.GetString("dialysis_remark")
-
- prescribing_number, _ := c.GetFloat("prescribing_number")
- prescription_sodium := c.GetString("prescription_sodium")
- start_sodium := c.GetString("start_sodium")
- sodium_curve := c.GetString("sodium_curve")
- treatment_remark := c.GetString("treatment_remark")
- dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
- sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
- prescription_water, _ := c.GetFloat("prescription_water")
- dialysis_strainer := c.GetString("dialysis_strainer")
- chaptalization := c.GetString("chaptalization")
- washing_time := c.GetString("washing_time")
- warsh_count := c.GetString("warsh_count")
- blood_access_part_id := c.GetString("blood_access_part_id")
- anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
- dialyzate := c.GetString("dialyzate")
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
-
- //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
- //
- //if template.TemplateId == 2 || template.TemplateId == 6 {
- // if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= recordDate.Unix() {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- if mode_id > 0 {
- var str string
- //查找该机构用的是什么透析器
- filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
- if filedConfig.ID > 0 {
- str = dialyzerPerfusionApparatus
- } else {
- str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
- }
- service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
- }
-
- goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
-
- var dialysis_dialyszers_id int64
- var dialysis_strainer_id int64
- var dialysis_irrigation_id int64
- if len(goodList) > 0 {
- for _, item := range goodList {
- if item.SpecificationName == dialysis_dialyszers {
- dialysis_dialyszers_id = item.ID
- }
- if item.SpecificationName == dialysis_irrigation {
- dialysis_irrigation_id = item.ID
- }
- if item.SpecificationName == dialysis_strainer {
- dialysis_strainer_id = item.ID
- }
- }
- }
-
- //TODO 需要根据角色去判断
-
- prescription := models.DialysisPrescription{
-
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- RecordDate: recordDate.Unix(),
- ModeId: mode_id,
- DialysisDuration: dialysis_duration,
- Dialyzer: dialyzer,
- PerfusionApparatus: perfusion_apparatus,
- BloodFlowVolume: blood_flow_volume,
- DewaterAmount: dewater_amount,
- DisplaceLiqui: displace_liqui,
- ReplacementWay: replacement_way,
- Anticoagulant: anticoagulant,
- AnticoagulantShouji: anticoagulant_shouji,
- AnticoagulantWeichi: anticoagulant_weichi,
- AnticoagulantZongliang: anticoagulant_zongliang,
- AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
- AnticoagulantGaijiliang: anticoagulant_gaijiliang,
- Kalium: kalium,
- Sodium: sodium,
- Calcium: calcium,
- Bicarbonate: bicarbonate,
- Glucose: glucose,
- // DryWeight: dry_weight,
- DialysateFlow: dialysate_flow,
- DialysateTemperature: dialysate_temperature,
- // PrescriptionDoctor: prescription_doctor,
- ReplacementTotal: replacement_total,
- Conductivity: conductivity,
- Remark: remark,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DialysisDurationMinute: dialysisDurationMinute,
- DialysisDurationHour: dialysisDurationHour,
- TargetUltrafiltration: targetUltrafiltration,
- DialysateFormulation: dialysateFormulation,
- DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
- BodyFluid: body_fluid,
- SpecialMedicine: special_medicine,
- SpecialMedicineOther: special_medicine_other,
- DisplaceLiquiPart: displace_liqui_part,
- DisplaceLiquiValue: displace_liqui_value,
- BloodAccess: blood_access,
- Ultrafiltration: ultrafiltration,
- BodyFluidOther: body_fluid_other,
- Niprocart: niprocart,
- Jms: jms,
- FistulaNeedleSet: fistula_needle_set,
- FistulaNeedleSet16: fistula_needle_set_16,
- Hemoperfusion: hemoperfusion,
- DialyserSterilised: dialyser_sterilised,
- Filtryzer: filtryzer,
- Dialyzers: dialyzers,
- Injector: injector,
- Bloodlines: bloodlines,
- TubingHemodialysis: tubing_hemodialysis,
- Package: safe_package,
- ALiquid: a_liquid,
- TargetKtv: target_ktv,
- PreImpulse: pre_impulse,
- AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
- AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
- Blood: blood,
- DialysisDialyszers: dialysis_dialyszers,
- DialysisIrrigation: dialysis_irrigation,
- AntioxidantCommodityName: antioxidant_commodity_name,
- DisplaceSpeed: displace_speed,
- Illness: illness,
- Amylaceum: amylaceum,
- SingleTime: single_time,
- SingleWater: single_water,
- ReplacementFlow: replacement_flow,
- PlasmaSeparator: plasma_separator,
- BilirubinAdsorptionColumn: bilirubin_adsorption_column,
- OxygenUptake: oxygen_uptake,
- OxygenFlow: oxygen_flow,
- OxygenTime: oxygen_time,
- HemodialysisPipelines: hemodialysis_pipelines,
- HemodialysisPipelinesCount: hemodialysis_pipelines_count,
- PunctureNeedle: puncture_needle,
- PunctureNeedleCount: puncture_needle_count,
- Epo: epo,
- EpoCount: epo_count,
- MaxUltrafiltrationRate: max_ultrafiltration_rate,
- AdminUserId: admin_user_id,
- IsWater: is_war,
- DrhyWater: drhy_water,
- DryWaterHour: dry_water_hour,
- WaterMachine: water_machine,
- AddAmount: add_amount,
- ReduceAmount: reduce_amount,
- DialysisRemark: dialysis_remark,
- PrescribingNumber: prescribing_number,
- StartSodium: start_sodium,
- SodiumCurve: sodium_curve,
- TreatmentRemark: treatment_remark,
- PrescriptionSodium: prescription_sodium,
- DialysisFluidFlow: dialysis_fluid_flow,
- SodiumBicarbonateFlow: sodium_bicarbonate_flow,
- PrescriptionWater: prescription_water,
- DialysisStrainer: dialysis_strainer,
- Chaptalization: chaptalization,
- WashingTime: washing_time,
- WarshCount: warsh_count,
- BloodAccessPartId: blood_access_part_id,
- AnticoagulantWeichiHour: anticoagulant_weichi_hour,
- Dialyzate: dialyzate,
- DialysisDialyszersId: dialysis_dialyszers_id,
- DialysisIrrigationId: dialysis_irrigation_id,
- DialysisStrainerId: dialysis_strainer_id,
- }
-
- if adminUserInfo.Org.Id == 10721 {
- if prescription.ModeId == 2 {
- if prescription.ReplacementTotal == 0 {
- prescription.ReplacementTotal = 15
- }
- }
-
- }
-
- //查询最近透析准备表里是否存在 透析器 灌流器
-
- //
- //splitStr := strings.Split(dialysis_dialyszers, ",")
- //
- //splitIrrigation := strings.Split(dialysis_irrigation, ",")
- //
- //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
- //if len(mation)>0{
- // for _, item := range splitStr {
- // for _,it := range mation{
- // if(item == it.SpecificationName){
- //
- // //查询最近一次的透析器
- // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
- //
- // if errcode == gorm.ErrRecordNotFound{
- // //插入数据
- // prepare := models.DialysisBeforePrepare{
- // UserOrgId: adminUserInfo.Org.Id,
- // PatientId: id,
- // RecordDate: recordDate.Unix(),
- // GoodTypeId: it.GoodTypeId,
- // GoodId: it.ID,
- // Count: 1,
- // Ctime: time.Now().Unix(),
- // Creater: adminUserInfo.AdminUser.Id,
- // Status:1,
- //
- // }
- // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
- // fmt.Println("",errcode)
- // }
- // }
- // }
- //
- // }
- //
- // for _, item := range splitIrrigation {
- // for _,it := range mation{
- // if(item == it.SpecificationName){
- // //查询最近一次的透析器
- // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
- // if errcode == gorm.ErrRecordNotFound{
- // //插入数据
- // prepare := models.DialysisBeforePrepare{
- // UserOrgId: adminUserInfo.Org.Id,
- // PatientId: id,
- // RecordDate: recordDate.Unix(),
- // GoodTypeId: it.GoodTypeId,
- // GoodId: it.ID,
- // Count: 1,
- // Ctime: time.Now().Unix(),
- // Creater: adminUserInfo.AdminUser.Id,
- // Status:1,
- //
- // }
- // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
- // fmt.Println(errcode)
- // }
- // }
- // }
- // }
- //}
-
- _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if dialysisPrescription.ID == 0 { //新增
-
- if appRole.UserType == 2 || appRole.UserType == 1 {
- prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
- }
-
- prescription.Creater = adminUserInfo.AdminUser.Id
-
- //针对河间咸得
- if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
-
- if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
-
- prescription.DisplaceLiquiPart = 0
- prescription.DisplaceLiquiValue = 0
- }
- }
- if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
- prescription.AdminUserId = adminUserInfo.AdminUser.Id
- }
- err := service.AddSigleRecord(&prescription)
-
- //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
- if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
-
- monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
-
- if len(monitorList) > 0 {
- var ultrafiltration_rate float64
- totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
-
- ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
- var replacement_rate float64
-
- //乘10 除10是为了保留一位小数
- replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
-
- var firstOpeateTime = monitorList[0].OperateTime
- for _, item := range monitorList {
- //超滤率
- service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
-
- //置换率
- service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
-
- //超滤量
- ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
- service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
-
- //置换量
- displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
-
- service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
-
- }
- }
-
- }
- //记录日志
- byterequest, _ := json.Marshal(prescription)
- prescriptionLog := models.XtDialysisPrescriptionLog{
- UserOrgId: prescription.UserOrgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- ErrLog: string(byterequest),
- AdminUserId: adminUserInfo.AdminUser.Id,
- RecordDate: prescription.RecordDate,
- PatientId: prescription.PatientId,
- Source: "手机端新增保存处方",
- Status: 1,
- }
-
- service.CreatePrescriptionLog(prescriptionLog)
-
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 1,
- RecordDate: recordDate.Unix(),
- Sourse: 1,
- PatientId: id,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
- //长沙南雅医院,自动生成抗凝剂的临时处方
- if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
-
- if prescribing_number == 0 {
- prescribing_number = 1
- }
- if prescribing_number == 0 && id == 14682 {
- prescribing_number = 2
- }
-
- if prescribing_number == 0 && id == 18560 {
- prescribing_number = 2
- }
- advice := models.DoctorAdvice{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- GroupNo: 0,
- AdviceType: 2,
- RecordDate: recordDate.Unix(),
- AdviceDate: recordDate.Unix(),
- StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
- AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
- AdviceDesc: "",
- ReminderDate: 0,
- SingleDose: anticoagulant_zongliang,
- SingleDoseUnit: "iu",
- DrugSpec: 0,
- DrugSpecUnit: "",
- PrescribingNumber: prescribing_number, // 前端传过来的开药数量
- PrescribingNumberUnit: "支",
- DeliveryWay: "静脉注射",
- ExecutionFrequency: "上机前",
- AdviceDoctor: 0,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- IsPrescription: 1,
- ExecutionState: 2,
- StopState: 2,
- IsSettle: 2,
- }
- // 查询排班信息
- schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if schedulePatient.ID > 0 {
- if schedulePatient.ScheduleType == 1 {
- advice.StartTime = recordDate.Unix() + 6.5*60*60
- }
-
- if schedulePatient.ScheduleType == 2 {
- advice.StartTime = recordDate.Unix() + 9*60*60
- }
- }
- // 抗凝剂名称
- switch anticoagulant {
- case 1:
- advice.AdviceName = "无肝素"
- break
- case 2:
- advice.AdviceName = "普通肝素"
- break
- case 3:
- advice.AdviceName = "低分子肝素"
- break
- case 4:
- advice.AdviceName = "阿加曲班"
- break
- case 5:
- advice.AdviceName = "枸橼酸钠"
- break
- case 6:
- advice.AdviceName = "低分子肝素钙"
- break
- case 7:
- advice.AdviceName = "低分子肝素钠"
- break
- case 8:
- advice.AdviceName = "依诺肝素"
- break
- case 9:
- advice.AdviceName = "达肝素"
- break
- case 10:
- advice.AdviceName = "体外抗凝"
- break
- case 11:
- advice.AdviceName = "那曲肝素"
- break
- case 12:
- advice.AdviceName = "无抗凝剂"
- break
- }
- //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
-
- if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
- advice.AdviceDoctor = appRole.AdminUserId
- }
-
- // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
- advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
- if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
- advice.AdviceName = "低分子肝素钠注射液"
- // 修改患者临时医嘱里的抗凝剂医嘱
- advice.ID = advicePrescription.ID
- service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
- } else {
- if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
- advice.AdviceName = "低分子肝素钠注射液"
- // 新增患者临时医嘱里的抗凝剂医嘱
- service.CreateDoctorAdvice(&advice)
- }
-
- }
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
- redis := service.RedisClient()
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
-
- }
-
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
- //清空key 值
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
-
- if err == nil {
- updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
-
- //清空key 值
- redis.Set(keyThree, "", time.Second)
-
- keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
- //清空key 值
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
- redis.Set(keyFive, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
-
- keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyOne, "", time.Second)
- if updateErr != nil {
- utils.ErrorLog("%v", updateErr)
- }
- defer redis.Close()
- c.ServeSuccessJSON(map[string]interface{}{
- "prescription": prescription,
- })
-
- }
- } else { //修改
-
- //if mode_id > 0 {
- // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
- //}
- //if template.TemplateId == 1 {
- // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- prescription.CreatedTime = dialysisPrescription.CreatedTime
- prescription.Modifier = adminUserInfo.AdminUser.Id
- if appRole.UserType == 2 || appRole.UserType == 1 {
- prescription_doctor := adminUserInfo.AdminUser.Id
- prescription.PrescriptionDoctor = prescription_doctor
- } else {
- prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
- }
-
- if dialysisPrescription.Creater == 0 { //体重称
- prescription.Creater = adminUserInfo.AdminUser.Id
-
- } else {
- prescription.Creater = dialysisPrescription.Creater
- if adminUserInfo.Org.Id == 9882 {
- if appRole.UserType == 2 || appRole.UserType == 1 {
- prescription_doctor := adminUserInfo.AdminUser.Id
- prescription.PrescriptionDoctor = prescription_doctor
- prescription.Creater = prescription_doctor
- }
- }
- }
-
- prescription.ID = dialysisPrescription.ID
-
- if adminUserInfo.Org.Id == 10721 {
- if prescription.ModeId == 2 {
- if prescription.ReplacementTotal == 0 {
- prescription.ReplacementTotal = 15
- }
- }
-
- }
-
- service.UpDateDialysisPrescription(&prescription)
-
- //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
- if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
-
- monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
-
- if len(monitorList) > 0 {
- var ultrafiltration_rate float64
- totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
-
- ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
- var replacement_rate float64
-
- //乘10 除10是为了保留一位小数
- replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
-
- var firstOpeateTime = monitorList[0].OperateTime
- for _, item := range monitorList {
- //超滤率
- service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
-
- //置换率
- service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
-
- //超滤量
- ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
- service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
-
- //置换量
- displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
-
- service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
-
- }
- }
-
- }
-
- //记录日志
- byterequest, _ := json.Marshal(prescription)
- prescriptionLog := models.XtDialysisPrescriptionLog{
- UserOrgId: prescription.UserOrgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- ErrLog: string(byterequest),
- AdminUserId: adminUserInfo.AdminUser.Id,
- RecordDate: prescription.RecordDate,
- PatientId: prescription.PatientId,
- Source: "手机端修改处方",
- Status: 1,
- }
-
- service.CreatePrescriptionLog(prescriptionLog)
-
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 1,
- RecordDate: recordDate.Unix(),
- Sourse: 1,
- PatientId: id,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
-
- //修改处方
- if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
- // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
- advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
- if advicePrescription.ID > 0 {
-
- service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
- redis := service.RedisClient()
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
- }
- }
-
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
-
- updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
- keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- //清空key 值
- redis.Set(keyTwoOne, "", time.Second)
- defer redis.Close()
- if updateErr != nil {
- utils.ErrorLog("%v", updateErr)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "prescription": prescription,
- })
-
- }
-
- }
-
- func (c *DialysisAPIController) Finish() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- nurseID, _ := c.GetInt64("nurse")
- end_time := c.GetString("end_time")
- puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
- internal_fistula := c.GetString("blood_access_internal_fistula")
- catheter := c.GetString("catheter")
- cruor := c.GetString("cruor")
- mission := c.GetString("mission")
- condenser := c.GetString("condenser")
- if id <= 0 || nurseID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
- if getNurseErr != nil {
- c.ErrorLog("获取护士失败:%v", getNurseErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- c.ErrorLog("护士不存在")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
- if parseEndDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= recordDate.Unix() {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- //now := time.Now()
- //year, month, day := now.Date()
- //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
- //todayTimeStamp := today_time.Unix()
-
- // 获取当天的第一条透析纪录
- fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
-
- if getMonitorRecordsErr != nil {
- c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- // 获取当前的最后一条透析纪录
- endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
- if getMonitorRecordsErr != nil {
- c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- fmt.Println(endmonitorRecords.UltrafiltrationVolume)
-
- assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
- if getAADErr != nil {
- c.ErrorLog("获取透后评估失败:%v", getAADErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
- lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
-
- _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
-
- var tempassessmentAfterDislysis models.AssessmentAfterDislysis
-
- if assessmentAfterDislysis != nil {
- tempassessmentAfterDislysis = *assessmentAfterDislysis
- tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
- } else {
- tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
- tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
- tempassessmentAfterDislysis.Status = 1
- tempassessmentAfterDislysis.PatientId = id
- tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
- }
-
- //长沙南雅
- if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
- //获取最后一条透析处方数据
- prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
- evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
- tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
- }
-
- if dialysisOrder.Stage == 1 {
- temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
- fmt.Println(value)
- a, b := math.Modf(value)
- c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
- hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
- minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
-
- tempassessmentAfterDislysis.ActualTreatmentHour = hour
- tempassessmentAfterDislysis.ActualTreatmentMinute = minute
-
- }
-
- if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
- //var num1 int64
- //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
- //fmt.Println(num1)
- //sub := float64(num1 / 3600)
- //fmt.Println(sub)
- //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
- //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
- //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
-
- tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
- tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
- tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
- if adminUserInfo.Org.Id != 10375 {
- tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
- tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
- }
-
- if adminUserInfo.Org.Id != 10445 {
- tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
- }
-
- //北方营口医院
- if adminUserInfo.Org.Id == 10445 {
- //获取最后一条透析处方数据
- lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
- tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
- } else {
- tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
- }
- //新化博翔
- if adminUserInfo.Org.Id == 10447 {
- tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
- }
-
- //阳春
- if adminUserInfo.Org.Id == 10485 {
- tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
- }
- if adminUserInfo.Org.Id == 10551 {
- //获取最后一条透析处方数据
- lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
- tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
- }
- if adminUserInfo.Org.Id == 10580 {
- tempassessmentAfterDislysis.ActualUltrafiltration = 0
- }
-
- if adminUserInfo.Org.Id == 10612 {
- tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
- }
-
- //孝康
- if adminUserInfo.Org.Id == 10693 {
- MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
- tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
- DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
- tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
- tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
-
- pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
- tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
-
- DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
- tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
-
- UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
- tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
- }
-
- if adminUserInfo.Org.Id == 10721 {
- tempassessmentAfterDislysis.DiastolicBloodPressure = 0
- tempassessmentAfterDislysis.SystolicBloodPressure = 0
- }
-
- if adminUserInfo.Org.Id == 10697 {
- lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
- floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
- lastWeightAfter.LastAfterWeight = floatAfeter
- }
-
- }
-
- 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 {
- evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
- if evaluation.SystolicBloodPressure == 0 {
- evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
-
- if adminUserInfo.Org.Id == 10693 {
- SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
- evaluation.SystolicBloodPressure = SystolicBloodPressureOne
- }
-
- pre := models.PredialysisEvaluation{
- SystolicBloodPressure: evaluation.SystolicBloodPressure,
- }
- fmt.Println("prew", pre)
- getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
-
- redis := service.RedisClient()
- redis.Set(key, "", time.Second)
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- fmt.Println(getNurseErr)
- }
-
- if evaluation.DiastolicBloodPressure == 0 {
- evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
-
- if adminUserInfo.Org.Id == 10693 {
- DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
- evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
- }
- pres := models.PredialysisEvaluation{
- DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
- }
-
- getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
-
- redis := service.RedisClient()
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- fmt.Println(getNurseErr)
- }
- if evaluation.PulseFrequency == 0 {
- evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
-
- if adminUserInfo.Org.Id == 10693 {
- pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
- evaluation.PulseFrequency = pulseFrequency
- }
- press := models.PredialysisEvaluation{
- PulseFrequency: evaluation.PulseFrequency,
- }
- getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
-
- redis := service.RedisClient()
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- fmt.Println(getNurseErr)
- }
-
- if evaluation.Temperature == 0 {
- evaluation.Temperature = fmonitorRecords.Temperature
- press := models.PredialysisEvaluation{
- Temperature: evaluation.Temperature,
- }
- getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
-
- redis := service.RedisClient()
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- fmt.Println(getNurseErr)
- }
- }
-
- if adminUserInfo.Org.Id == 9583 {
- //获取透析处方的最后一条数据
- diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
- if diaerr != nil {
- c.ErrorLog("获取透析处方失败:%v", diaerr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
-
- tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
- }
-
- }
-
- if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
-
- tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
- }
-
- if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
-
- tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
- }
-
- if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
- tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
- }
-
- if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
- tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
- }
-
- if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
- tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
- tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
- }
-
- if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
- tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
- tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
- }
-
- if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
- tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
- tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
- tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
- tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
- }
-
- if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
- tempassessmentAfterDislysis.SystolicBloodPressure = 0
- tempassessmentAfterDislysis.DiastolicBloodPressure = 0
- }
-
- if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
- tempassessmentAfterDislysis.SystolicBloodPressure = 0
- tempassessmentAfterDislysis.DiastolicBloodPressure = 0
- }
-
- if lastAssessmentAfterDislysis != nil {
- tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
-
- tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
-
- tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
- tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
- tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
- tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
- tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
- tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
- tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
- tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
- tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
-
- tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
-
- tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
- tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
-
- tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
- tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
- tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
- tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
-
- tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
- tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
- tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
- tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
-
- tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
- tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
- tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
-
- tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
- tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
- tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
-
- tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
- tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
- tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
-
- tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
- tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
- tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
- tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
-
- tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
- tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
- tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
- tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
- tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
- tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
- tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
- tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
- tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
- tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
- tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
- tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
- tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
- if tempassessmentAfterDislysis.PatientId == 18695 {
- tempassessmentAfterDislysis.ActualDisplacement = 0
- }
-
- if adminUserInfo.Org.Id != 10375 {
- tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
- tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
- }
-
- if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
- tempassessmentAfterDislysis.SystolicBloodPressure = 0
- tempassessmentAfterDislysis.DiastolicBloodPressure = 0
- }
-
- if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
- tempassessmentAfterDislysis.SystolicBloodPressure = 0
- tempassessmentAfterDislysis.DiastolicBloodPressure = 0
- }
-
- }
-
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 9,
- RecordDate: tempassessmentAfterDislysis.AssessmentDate,
- Sourse: 1,
- PatientId: tempassessmentAfterDislysis.PatientId,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
-
- //孝康
- if adminUserInfo.Org.Id == 10693 {
- MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
- tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
-
- DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
-
- tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
-
- MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
-
- tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
-
- DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
- tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
-
- UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
- tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
- }
-
- if adminUserInfo.Org.Id == 10697 {
- lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
- floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
- lastWeightAfter.LastAfterWeight = floatAfeter
- }
-
- if adminUserInfo.Org.Id == 10721 {
- tempassessmentAfterDislysis.DiastolicBloodPressure = 0
- tempassessmentAfterDislysis.SystolicBloodPressure = 0
- }
-
- err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
- redis := service.RedisClient()
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
- redis.Set(keyTwo, "", time.Second)
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if dialysisOrder == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
- return
- }
- if dialysisOrder.Stage == 2 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
- return
- }
-
- if dialysisOrder.Stage == 1 {
- err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 8,
- RecordDate: recordDate.Unix(),
- Sourse: 1,
- PatientId: id,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
- redis := service.RedisClient()
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
- redis.Set(keyOne, "", time.Second)
- //结束时候透析次数加1
- service.UpdateSolutionByPatientId(id)
-
- //下机完自动消毒,针对长沙南雅
- if dialysisOrder.Stage == 1 {
- 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 {
- //根据床位号获取设备型号
- unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
- //查询使用消毒最后一条消毒记录
- _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
- fmt.Println("err", err)
- if err == gorm.ErrRecordNotFound {
- //查找排班
- scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
- //查询改设备是否有消毒计划
- plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
-
- //根据床位号获取设备id
- addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
-
- //查询病人信息
- patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
- var con = ""
- if patients.IsInfectious == 0 {
- con = ""
- }
- if patients.IsInfectious == 1 {
- con = "无"
- }
- if patients.IsInfectious == 2 {
- con = "有"
- }
-
- if errcode == nil {
- var end_time int64
- end_time = endDate.Unix() + plan.DisinfecTime*60
- //新增消毒
- information := models.DeviceInformation{
- Date: dialysisOrder.DialysisDate,
- Zone: dialysisOrder.ZoneId,
- Class: dialysisOrder.SchedualType,
- BedNumber: dialysisOrder.BedID,
- PatientId: dialysisOrder.PatientId,
- DialysisMode: scheduleByPatient.ModeId,
- LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
- Disinfection: 1,
- DialysisConcentration: 1,
- DisinfectionStatus: 1,
- Move: 1,
- UserOrgId: dialysisOrder.UserOrgId,
- DisinfectType: plan.Way,
- DisinfectantType: plan.MachineDisinfectant,
- FluidPath: plan.DisinfectanWay, //液路消毒方式
- Disinfectant: plan.Disinfectant,
- Ctime: time.Now().Unix(),
- Status: 1,
- SignName: nurseID,
- EquimentId: addmacher.ID,
- DisinfectionResidue: 2,
- Bed: addmacher.BedNumber,
- StartTime: dialysisOrder.StartTime,
- EndTime: dialysisOrder.EndTime,
- Contagion: con,
- WeightLoss: 0,
- Hyperfiltratio: 0,
- DialysisHour: "",
- MachineRun: 1,
- DisinfecStartime: endDate.Unix(),
- DisinfecEndtime: end_time,
- }
- err := service.CreateInformationTwo(&information)
- fmt.Println("报错", err)
- }
- }
- }
-
- }
-
- dialysisOrder.Stage = 2
- dialysisOrder.FinishNurse = nurseID
- dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
- dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
- dialysisOrder.EndTime = endDate.Unix()
-
- // 长沙南雅需求
- if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
-
- //获取最后1条监测的数据
- fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
- lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
- var accumulatedBloodVolume float64
- accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
-
- err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
- fmt.Println(err)
-
- // 查询未执行的医嘱
- doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
-
- for _, item := range doctorAdvice {
- service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
- theTime := toTime.Format("2006-01-02")
- keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- defer redis.Close()
- }
- }
-
- go func() {
- ssoDomain := beego.AppConfig.String("call_domain")
- api := ssoDomain + "/index/downpatient"
- values := make(url.Values)
- values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
- values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
- values.Set("patient_id", strconv.FormatInt(id, 10))
- http.PostForm(api, values)
- }()
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "dialysisOrder": dialysisOrder,
- "assessmentAfterDislysis": tempassessmentAfterDislysis,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
-
- }
-
- func (c *DialysisAPIController) GetAllZone() {
- adminUserInfo := c.GetMobileAdminUserInfo()
- err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "zone": zone,
- })
- }
-
- }
-
- func (c *DialysisAPIController) GetSchedualPatientsList() {
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 10)
- schedulType, _ := c.GetInt64("schedul_type", 0)
- startTime, _ := c.GetInt64("schedul_time", 0)
- partitionType, _ := c.GetInt64("partition_type", 0)
- keywords := c.GetString("keywords")
- dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "schedule": dialysisSchedule,
- })
- }
- return
- }
-
- // /m/api/dialysis/start [post]
- // @param patient_id:int
- // @param record_date:string 排班时间 (yyyy-mm-dd)
- // @param nurse:int 上机护士
- // @param bed:int 床位号
- func (this *DialysisAPIController) StartDialysis() {
- patientID, _ := this.GetInt64("patient_id")
- recordDateStr := this.GetString("record_date")
- nurseID, _ := this.GetInt64("start_nurse")
- puncture_nurse, _ := this.GetInt64("puncture_nurse")
- blood_drawing, _ := this.GetInt64("blood_drawing")
- schedual_type, _ := this.GetInt64("schedual_type")
-
- bedID, _ := this.GetInt64("bed")
- start_time := this.GetString("start_time")
- washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
- change_nurse, _ := this.GetInt64("change_nurse")
- difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
- new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
- quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
- puncture_needle := this.GetString("puncture_needle")
- puncture_way := this.GetString("puncture_way")
- dialysis_dialyszers := this.GetString("dialysis_dialyszers")
- dialysis_irrigation := this.GetString("dialysis_irrigation")
- blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
- zone_id, _ := this.GetInt64("zone_id")
- elecsign := this.GetString("url")
- nuclein_date_str := this.GetString("nuclein_date_str")
- schedule_remark := this.GetString("schedule_remark")
- order_remark := this.GetString("order_remark")
- catheter_operation := this.GetString("catheter_operation")
- blood_flow_volume := this.GetString("blood_flow_volume")
- dialysis_strainer := this.GetString("dialysis_strainer")
- if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
- if parseStartDateErr != nil {
- this.ErrorLog("时间解析失败:%v", parseStartDateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseErr != nil {
- this.ErrorLog("时间解析失败:%v", parseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetMobileAdminUserInfo()
- patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
- if getPatientErr != nil {
- this.ErrorLog("获取患者信息失败:%v", getPatientErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if patient == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
- if getNurseErr != nil {
- this.ErrorLog("获取护士失败:%v", getNurseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- this.ErrorLog("护士不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
-
- deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
- if getDeviceNumberErr != nil {
- this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if deviceNumber == nil {
- this.ErrorLog("床位号不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
- if getRecordErr != nil {
- this.ErrorLog("获取透析记录失败:%v", getRecordErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if dialysisRecord != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
- return
- }
-
- scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
- scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
- schedulestartTime := theStartTime.Unix()
- scheduleendTime := theEndTime.Unix()
-
- var theNucleinDate int64
- timeLayoutOne := "2006-01-02"
- if len(nuclein_date_str) > 0 {
- theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- }
- theNucleinDate = theTime.Unix()
- }
-
- template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
-
- //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
- //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
-
- schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
-
- //查询该床位是否有人用了
- order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
-
- if err == gorm.ErrRecordNotFound { //空床位
- // 修改了床位逻辑
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
- if daySchedule.ID > 0 {
- daySchedule.PartitionId = deviceNumber.ZoneID
- daySchedule.BedId = bedID
- daySchedule.ScheduleType = schedual_type
- daySchedule.UpdatedTime = time.Now().Unix()
- xtSchedule := models.Schedule{
- PartitionId: deviceNumber.ZoneID,
- BedId: bedID,
- ScheduleType: schedual_type,
- UpdatedTime: time.Now().Unix(),
- }
- err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- } else if err == nil {
- if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
-
- if order.ID > 0 { //该机位被其他人占用了
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
- return
- } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
- if daySchedule.ID > 0 {
- err := service.UpdateScheduleTwo(daySchedule, schedule)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- }
- }
- } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
- return
- }
- //else if order.ID == 0 { //该床位没被占用
- // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
- // if daySchedule.ID > 0 {
- // //daySchedule.PartitionId = deviceNumber.ZoneID
- // //daySchedule.BedId = bedID
- // //daySchedule.ScheduleType = schedual_type
- // //daySchedule.UpdatedTime = time.Now().Unix()
- // //err := service.UpdateSchedule(&daySchedule)
- // xtSchedule := models.Schedule{
- // PartitionId: deviceNumber.ZoneID,
- // BedId: bedID,
- // ScheduleType: schedual_type,
- // UpdatedTime: time.Now().Unix(),
- // }
- // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
- // if err != nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
- // }
- //}
- //}
-
- } else if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= recordDate.Unix() {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- dialysisRecord = &models.DialysisOrder{
- DialysisDate: recordDate.Unix(),
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: patientID,
- Stage: 1,
- BedID: bedID,
- StartNurse: nurseID,
- Status: 1,
- StartTime: startDate.Unix(),
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- PunctureNurse: puncture_nurse,
- Creator: adminUserInfo.AdminUser.Id,
- Modifier: adminUserInfo.AdminUser.Id,
- SchedualType: schedual_type,
- WashpipeNurse: washpipe_nurse,
- ChangeNurse: change_nurse,
- DifficultPunctureNurse: difficult_puncture_nurse,
- NewFistulaNurse: new_fistula_nurse,
- ZoneId: zone_id,
- QualityNurseId: quality_nurse_id,
- PunctureNeedle: puncture_needle,
- PunctureWay: puncture_way,
- DialysisIrrigation: dialysis_irrigation,
- DialysisDialyszers: dialysis_dialyszers,
- BloodAccessId: blood_access_id,
- Url: elecsign,
- NucleinDate: theNucleinDate,
- ScheduleRemark: schedule_remark,
- OrderRemark: order_remark,
- CatheterOperation: catheter_operation,
- BloodFlowVolume: blood_flow_volume,
- BloodDrawing: blood_drawing,
- DialysisStrainer: dialysis_strainer,
- }
- //查询该床位是否有人用了
- _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
- if errorscode == gorm.ErrRecordNotFound {
-
- createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 6,
- RecordDate: schedulestartTime,
- Sourse: 1,
- PatientId: patientID,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
- service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
-
- if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
- //统计该患者总次数
- dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
- service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
- }
-
- if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
- //统计该患者总次数
- dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
- service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
- }
-
- redis := service.RedisClient()
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyTwo, "", time.Second)
-
- if createErr != nil {
- this.ErrorLog("上机失败:%v", createErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
-
- var tempdispose string
- // 只针对中能建
- if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
- tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
- }
-
- if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
- tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
- }
-
- //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
- // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
- //}
-
- var ultrafiltration_rate float64
- var ultrafiltration_rate_one string
- var replacement_rate float64
- _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
- //后期预增脱水量
- _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
-
- if prescription.ID > 0 {
- if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
-
- totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
- 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
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
- }
-
- if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
- ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
- }
-
- //针对医师汇
- if adminUserInfo.Org.Id == 10121 {
- dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
- ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
- }
-
- //针对通道
-
- if adminUserInfo.Org.Id == 10234 {
- ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
- }
-
- //针对监利大垸医院
- if template.TemplateId == 41 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
- }
-
- //针对肇庆三鹤血液透析中心
-
- if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
- }
-
- if adminUserInfo.Org.Id == 10469 {
- ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
- }
-
- if adminUserInfo.Org.Id == 10667 {
- ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
- }
-
- if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
- }
-
- // 只针对方济医院
- if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
- ultrafiltration_rate = value
- }
-
- //针对
- if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
-
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
- ultrafiltration_rate = ultrafiltration_rate / 1000
- }
-
- if adminUserInfo.Org.Id == 10551 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
- ultrafiltration_rate = ultrafiltration_rate / 1000
- }
-
- if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
- ultrafiltration_rate = ultrafiltration_rate / 1000
- }
-
- if adminUserInfo.Org.Id == 10580 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
- ultrafiltration_rate = ultrafiltration_rate / 1000
- }
-
- if adminUserInfo.Org.Id == 10629 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
- ultrafiltration_rate = ultrafiltration_rate / 1000
- }
-
- if adminUserInfo.Org.Id == 10644 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
- ultrafiltration_rate = ultrafiltration_rate / 1000
- }
-
- if adminUserInfo.Org.Id == 10667 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
- ultrafiltration_rate = ultrafiltration_rate / 1000
- }
-
- if adminUserInfo.Org.Id == 10693 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
- ultrafiltration_rate = ultrafiltration_rate
- ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
-
- }
-
- if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
- ultrafiltration_rate = ultrafiltration_rate
- }
-
- if adminUserInfo.Org.Id == 10702 {
- ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
- ultrafiltration_rate = ultrafiltration_rate / 1000
- }
-
- if adminUserInfo.Org.Id == 10723 {
- ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
- ultrafiltration_rate = ultrafiltration_rate / 1000
- }
-
- if adminUserInfo.Org.Id == 10721 {
- ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
- ultrafiltration_rate = ultrafiltration_rate / 1000
- }
-
- }
- }
-
- record := models.MonitoringRecord{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: patientID,
- DialysisOrderId: dialysisRecord.ID,
- MonitoringDate: schedulestartTime,
- OperateTime: startDate.Unix(),
- // MonitoringTime: recordTime,
- MonitoringNurse: nurseID,
- Dispose: tempdispose,
- UltrafiltrationRate: ultrafiltration_rate,
- UltrafiltrationVolume: 0,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- UltrafiltrationRateOne: ultrafiltration_rate_one,
- ReplacementRate: replacement_rate,
- }
-
- //只针对广慈医院
- 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 {
- // 查询病人是否有透前评估数据
- befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
-
- //如果有数据就插入
- if errcode == nil {
- record.SystolicBloodPressure = befor.SystolicBloodPressure
- record.DiastolicBloodPressure = befor.DiastolicBloodPressure
- record.BreathingRate = befor.BreathingRate
- record.PulseFrequency = befor.PulseFrequency
- record.Temperature = befor.Temperature
- }
- }
-
- //孝昌
- if adminUserInfo.Org.Id == 10693 {
- // 查询病人是否有透前评估数据
- befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
-
- //如果有数据就插入
- if errcode == nil {
- record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
- record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
- record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
- record.BreathingRate = befor.BreathingRate
- }
- }
-
- // 如果当天有插入数据,则不再往透析纪录里插入数据
- if newdialysisRecord.ID > 0 {
- if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
- record.Temperature = 36.5
- record.ArterialPressure = -100
- record.DialysateTemperature = 36.5
- record.Conductivity = 14
- record.BreathingRate = "20"
- record.VenousPressure = 80
- record.TransmembranePressure = 60
- record.Dispose = catheter_operation
- }
- //针对新化博翔
- if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
- record.BloodOxygenSaturation = "99"
- record.Conductivity = 14
- record.DialysateTemperature = 36.5
- record.BreathingRate = "20"
- }
- //针对兰溪人民医院的需求
- if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
- befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
- record.SystolicBloodPressure = befor.SystolicBloodPressure
- record.DiastolicBloodPressure = befor.DiastolicBloodPressure
- record.Temperature = befor.Temperature
- record.PulseFrequency = befor.PulseFrequency
- record.BreathingRate = befor.BreathingRate
- }
-
- //针对乐山友谊医院的需求
- if adminUserInfo.Org.Id == 10677 {
- befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
- record.SystolicBloodPressure = befor.SystolicBloodPressure
- record.DiastolicBloodPressure = befor.DiastolicBloodPressure
- record.Temperature = befor.Temperature
- record.PulseFrequency = befor.PulseFrequency
- record.BreathingRate = befor.BreathingRate
- }
- //新化博翔
- if adminUserInfo.Org.Id == 10447 {
- befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
- record.SystolicBloodPressure = befor.SystolicBloodPressure
- record.DiastolicBloodPressure = befor.DiastolicBloodPressure
- record.BreathingRate = befor.BreathingRate
- }
-
- if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
- record.PulseFrequency = 80
- record.Temperature = 36.5
- }
-
- //诊断灵山圣康
- if adminUserInfo.Org.Id == 10375 {
- record.Conductivity = 13.8
- record.DialysateTemperature = 37
- record.DialysateFlow = 500
- record.BloodFlowVolume = 200
- record.BreathingRate = "18"
- record.SodiumConcentration = 140
- }
- //江成肾病医院
- if adminUserInfo.Org.Id == 10517 {
- record.SodiumConcentration = 138
- record.DialysateTemperature = 36.5
- }
-
- //濉溪杏康血液透析中心
- if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
- record.BloodFlowVolume = prescription.BloodFlowVolume
- }
-
- if adminUserInfo.Org.Id != 10683 {
- err = service.CreateMonitor(&record)
- }
-
- //记录日志
- byterequest, _ := json.Marshal(record)
- monitorRecordLog := models.XtMonitorRecordLog{
- RecordDate: record.MonitoringDate,
- PatientId: record.PatientId,
- Module: 1,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- UserOrgId: record.UserOrgId,
- ErrLog: string(byterequest),
- Source: "执行上机时新增监测",
- }
- service.CreateMonitorRecordLog(monitorRecordLog)
-
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 7,
- RecordDate: schedulestartTime,
- Sourse: 1,
- PatientId: patientID,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
-
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
- return
- }
- }
-
- go func() {
- ssoDomain := beego.AppConfig.String("call_domain")
- api := ssoDomain + "/index/uppatient"
- values := make(url.Values)
- values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
- values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
- values.Set("patient_id", strconv.FormatInt(patientID, 10))
- values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
- http.PostForm(api, values)
- }()
-
- this.ServeSuccessJSON(map[string]interface{}{
-
- "dialysis_order": newdialysisRecord,
- "monitor": record,
- })
- return
- }
-
- func (c *DialysisAPIController) PostSolution() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- mode_id, _ := c.GetInt64("mode_id", 0)
- dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
- dialyzer, _ := c.GetInt64("dialyzer", 0)
- perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
- blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
- dewater_amount, _ := c.GetFloat("dewater_amount", 0)
- displace_liqui, _ := c.GetFloat("displace_liqui", 0)
- replacement_way, _ := c.GetInt64("replacement_way", 0)
- anticoagulant, _ := c.GetInt64("anticoagulant", 0)
- anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
- anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
- anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
- anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
- anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
- kalium, _ := c.GetFloat("kalium", 0)
- sodium, _ := c.GetFloat("sodium", 0)
- calcium, _ := c.GetFloat("calcium", 0)
- bicarbonate, _ := c.GetFloat("bicarbonate", 0)
- prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
- dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
-
- glucose, _ := c.GetFloat("glucose", 0)
- // dry_weight, _ := c.GetFloat("dry_weight", 0)
- dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
- dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
- conductivity, _ := c.GetFloat("conductivity", 0)
- remark := c.GetString("remark")
- dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
- dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
- targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
- dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
- body_fluid, _ := c.GetInt64("body_fluid", 0)
- special_medicine, _ := c.GetInt64("special_medicine", 0)
- special_medicine_other := c.GetString("special_medicine_other")
- displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
- displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
- blood_access, _ := c.GetInt64("blood_access", 0)
- ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
- body_fluid_other := c.GetString("body_fluid_other")
- replacement_total, _ := c.GetFloat("replacement_total", 0)
-
- niprocart, _ := c.GetInt64("niprocart", 0)
- jms, _ := c.GetInt64("jms", 0)
- fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
- fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
- hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
- dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
- filtryzer, _ := c.GetInt64("filtryzer", 0)
-
- target_ktv, _ := c.GetFloat("target_ktv", 0)
-
- dialyzers, _ := c.GetInt64("dialyzers", 0)
- injector, _ := c.GetInt64("injector", 0)
- bloodlines, _ := c.GetInt64("bloodlines", 0)
- tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
- safe_package, _ := c.GetInt64("package", 0)
- a_liquid, _ := c.GetInt64("a_liquid", 0)
-
- anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
- anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
- blood := c.GetString("blood")
- dialysis_dialyszers := c.GetString("dialysis_dialyszers")
- dialysis_irrigation := c.GetString("dialysis_irrigation")
- antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
- displace_speed := c.GetString("displace_speed")
- illness, _ := c.GetInt64("illness")
- amylaceum := c.GetString("amylaceum")
- single_time := c.GetString("single_time")
- single_water := c.GetString("single_water")
- replacement_flow := c.GetString("replacement_flow")
- plasma_separator := c.GetString("plasma_separator")
- bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
- oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
- oxygen_flow := c.GetString("oxygen_flow")
- oxygen_time := c.GetString("oxygen_time")
-
- hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
- hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
-
- puncture_needle := c.GetString("puncture_needle")
- puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
-
- epo := c.GetString("epo")
- epo_count, _ := c.GetFloat("epo_count", 0)
- max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
- pre_impulse := c.GetString("pre_impulse")
- impulse, _ := strconv.ParseFloat(pre_impulse, 64)
- admin_user_id, _ := c.GetInt64("admin_user_id")
-
- is_water := c.GetString("is_water")
- add_amount, _ := c.GetFloat("add_amount")
- reduce_amount, _ := c.GetFloat("reduce_amount")
-
- prescribing_number, _ := c.GetFloat("prescribing_number")
- treatment_remark := c.GetString("treatment_remark")
- prescription_sodium := c.GetString("prescription_sodium")
- start_sodium := c.GetString("start_sodium")
- sodium_curve := c.GetString("sodium_curve")
- var is_war int64
- if is_water == "是" {
- is_war = 1
- }
- if is_water == "否" {
- is_war = 2
- }
- if is_water == "请选择" {
- is_war = 0
- }
- drhy_water := c.GetString("drhy_water")
- dry_water_hour := c.GetString("dry_water_hour")
- water_machine := c.GetString("water_machine")
- dialysis_remark := c.GetString("dialysis_remark")
- dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
- sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
- prescription_water, _ := c.GetFloat("prescription_water")
- dialysis_strainer := c.GetString("dialysis_strainer")
- chaptalization := c.GetString("chaptalization")
- washing_time := c.GetString("washing_time")
- warsh_count := c.GetString("warsh_count")
- blood_access_part_id := c.GetString("blood_access_part_id")
- anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
- dialyzate := c.GetString("dialyzate")
- if mode_id > 0 {
-
- var str string
- //查找该机构用的是什么透析器
- filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
- if filedConfig.ID > 0 {
- str = dialyzerPerfusionApparatus
- } else {
- str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
- }
- service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
- }
-
- //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
- //
- //if template.TemplateId == 2 || template.TemplateId == 6 {
- // if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= recordDate.Unix() {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
-
- var dialysis_dialyszers_id int64
- var dialysis_strainer_id int64
- var dialysis_irrigation_id int64
- if len(goodList) > 0 {
- for _, item := range goodList {
- if item.SpecificationName == dialysis_dialyszers {
- dialysis_dialyszers_id = item.ID
- }
- if item.SpecificationName == dialysis_irrigation {
- dialysis_irrigation_id = item.ID
- }
- if item.SpecificationName == dialysis_strainer {
- dialysis_strainer_id = item.ID
- }
- }
- }
-
- prescription := models.DialysisPrescription{
-
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- RecordDate: recordDate.Unix(),
- ModeId: mode_id,
- DialysisDuration: dialysis_duration,
- Dialyzer: dialyzer,
- PerfusionApparatus: perfusion_apparatus,
- BloodFlowVolume: blood_flow_volume,
- DewaterAmount: dewater_amount,
- DisplaceLiqui: displace_liqui,
- ReplacementWay: replacement_way,
- Anticoagulant: anticoagulant,
-
- AnticoagulantShouji: anticoagulant_shouji,
- AnticoagulantWeichi: anticoagulant_weichi,
- AnticoagulantZongliang: anticoagulant_zongliang,
- AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
- AnticoagulantGaijiliang: anticoagulant_gaijiliang,
- Kalium: kalium,
- Sodium: sodium,
- Calcium: calcium,
- Bicarbonate: bicarbonate,
- Glucose: glucose,
- // DryWeight: dry_weight,
- DialysateFlow: dialysate_flow,
- DialysateTemperature: dialysate_temperature,
- Conductivity: conductivity,
- Remark: remark,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DialysisDurationMinute: dialysisDurationMinute,
- DialysisDurationHour: dialysisDurationHour,
- TargetUltrafiltration: targetUltrafiltration,
- DialysateFormulation: dialysateFormulation,
- DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
- BodyFluid: body_fluid,
-
- SpecialMedicine: special_medicine,
- SpecialMedicineOther: special_medicine_other,
- DisplaceLiquiPart: displace_liqui_part,
- DisplaceLiquiValue: displace_liqui_value,
- BloodAccess: blood_access,
- Ultrafiltration: ultrafiltration,
- BodyFluidOther: body_fluid_other,
- ReplacementTotal: replacement_total,
- Niprocart: niprocart,
- Jms: jms,
- FistulaNeedleSet: fistula_needle_set,
- FistulaNeedleSet16: fistula_needle_set_16,
- Hemoperfusion: hemoperfusion,
- DialyserSterilised: dialyser_sterilised,
- Filtryzer: filtryzer,
- TargetKtv: target_ktv,
- Dialyzers: dialyzers,
- Injector: injector,
- Bloodlines: bloodlines,
- TubingHemodialysis: tubing_hemodialysis,
- Package: safe_package,
- ALiquid: a_liquid,
- AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
- AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
- Blood: blood,
- DialysisDialyszers: dialysis_dialyszers,
- DialysisIrrigation: dialysis_irrigation,
- AntioxidantCommodityName: antioxidant_commodity_name,
- DisplaceSpeed: displace_speed,
- Illness: illness,
- Amylaceum: amylaceum,
- SingleWater: single_water,
- SingleTime: single_time,
- ReplacementFlow: replacement_flow,
- PlasmaSeparator: plasma_separator,
- BilirubinAdsorptionColumn: bilirubin_adsorption_column,
- OxygenUptake: oxygen_uptake,
- OxygenTime: oxygen_time,
- OxygenFlow: oxygen_flow,
- HemodialysisPipelines: hemodialysis_pipelines,
- HemodialysisPipelinesCount: hemodialysis_pipelines_count,
- PunctureNeedle: puncture_needle,
- PunctureNeedleCount: puncture_needle_count,
- Epo: epo,
- EpoCount: epo_count,
- MaxUltrafiltrationRate: max_ultrafiltration_rate,
- PreImpulse: impulse,
- AdminUserId: admin_user_id,
- IsWater: is_war,
- DrhyWater: drhy_water,
- DryWaterHour: dry_water_hour,
- WaterMachine: water_machine,
- AddAmount: add_amount,
- ReduceAmount: reduce_amount,
- DialysisRemark: dialysis_remark,
- PrescribingNumber: prescribing_number,
- PrescriptionSodium: prescription_sodium,
- StartSodium: start_sodium,
- SodiumCurve: sodium_curve,
- TreatmentRemark: treatment_remark,
- DialysisFluidFlow: dialysis_fluid_flow,
- SodiumBicarbonateFlow: sodium_bicarbonate_flow,
- PrescriptionWater: prescription_water,
- DialysisStrainer: dialysis_strainer,
- Chaptalization: chaptalization,
- WashingTime: washing_time,
- WarshCount: warsh_count,
- BloodAccessPartId: blood_access_part_id,
- AnticoagulantWeichiHour: anticoagulant_weichi_hour,
- Dialyzate: dialyzate,
- DialysisDialyszersId: dialysis_dialyszers_id,
- DialysisIrrigationId: dialysis_irrigation_id,
- DialysisStrainerId: dialysis_strainer_id,
- }
-
- if adminUserInfo.Org.Id == 10721 {
- if prescription.ModeId == 2 {
- if prescription.ReplacementTotal == 0 {
- prescription.ReplacementTotal = 15
- }
-
- }
- }
-
- _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
-
- //
- if appRole.UserType == 2 || appRole.UserType == 1 {
- prescription_doctor = adminUserInfo.AdminUser.Id
- prescription.PrescriptionDoctor = prescription_doctor
-
- }
-
- if dialysisPrescription.ID == 0 { //新增
- prescription.Creater = adminUserInfo.AdminUser.Id
- if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
- prescription.AdminUserId = adminUserInfo.AdminUser.Id
- }
- } else { //修改
- if dialysisPrescription.Creater == 0 {
- prescription.Creater = adminUserInfo.AdminUser.Id
- } else {
-
- prescription.Creater = dialysisPrescription.Creater
- if adminUserInfo.Org.Id == 9882 {
- if appRole.UserType == 2 || appRole.UserType == 1 {
- prescription.Creater = adminUserInfo.AdminUser.Id
- prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
-
- }
- }
- }
-
- if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
- prescription.AdminUserId = adminUserInfo.AdminUser.Id
- }
-
- //if/**/
- //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
-
- //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- //prescription.Creater = dialysisPrescription.Creater
- prescription.CreatedTime = dialysisPrescription.CreatedTime
- prescription.Modifier = adminUserInfo.AdminUser.Id
- prescription.ID = dialysisPrescription.ID
- }
-
- solution := models.DialysisSolution{
- RegistrarsId: adminUserInfo.AdminUser.Id,
- UserOrgId: adminUserInfo.Org.Id,
- Doctor: prescription_doctor,
- PatientId: id,
- ModeId: mode_id,
- DialysisDuration: dialysis_duration,
- PerfusionApparatus: perfusion_apparatus,
- BloodFlowVolume: blood_flow_volume,
- Dewater: dewater_amount,
- DisplaceLiqui: displace_liqui,
- ReplacementWay: replacement_way,
- Anticoagulant: anticoagulant,
- AnticoagulantShouji: anticoagulant_shouji,
- AnticoagulantWeichi: anticoagulant_weichi,
- AnticoagulantZongliang: anticoagulant_zongliang,
- AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
- AnticoagulantGaijiliang: anticoagulant_gaijiliang,
- Kalium: kalium,
- Sodium: sodium,
- Calcium: calcium,
- Bicarbonate: bicarbonate,
- Glucose: glucose,
- // DryWeight: dry_weight,
- DialysateFlow: dialysate_flow,
- DialysateTemperature: dialysate_temperature,
- Conductivity: conductivity,
- Remark: remark,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DialysisDurationMinute: dialysisDurationMinute,
- DialysisDurationHour: dialysisDurationHour,
- TargetUltrafiltration: targetUltrafiltration,
- DialysateFormulation: dialysateFormulation,
- DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
- BodyFluid: body_fluid,
- SpecialMedicine: special_medicine,
- SpecialMedicineOther: special_medicine_other,
- DisplaceLiquiPart: displace_liqui_part,
- DisplaceLiquiValue: displace_liqui_value,
- BloodAccess: blood_access,
- Ultrafiltration: ultrafiltration,
- BodyFluidOther: body_fluid_other,
- ReplacementTotal: replacement_total,
- TargetKtv: target_ktv,
- DialysisDialyszers: dialysis_dialyszers,
- DialysisIrrigation: dialysis_irrigation,
- HemodialysisPipelines: hemodialysis_pipelines,
- HemodialysisPipelinesCount: hemodialysis_pipelines_count,
- PunctureNeedle: puncture_needle,
- PunctureNeedleCount: puncture_needle_count,
- Epo: epo,
- EpoCount: epo_count,
- MaxUltrafiltrationRate: max_ultrafiltration_rate,
- PreImpulse: impulse,
- SolutionStatus: 1,
- DialysisRemark: dialysis_remark,
- PrescribingNumber: prescribing_number,
- PrescriptionSodium: prescription_sodium,
- StartSodium: start_sodium,
- SodiumCurve: sodium_curve,
- TreatmentRemark: treatment_remark,
- SodiumBicarbonateFlow: sodium_bicarbonate_flow,
- DialysisFluidFlow: dialysis_fluid_flow,
- PrescriptionWater: prescription_water,
- DialysisStrainer: dialysis_strainer,
- Chaptalization: chaptalization,
- WashingTime: washing_time,
- WarshCount: warsh_count,
- BloodAccessPartId: blood_access_part_id,
- AnticoagulantWeichiHour: anticoagulant_weichi_hour,
- Dialyzate: dialyzate,
- DialysisDialyszersId: dialysis_dialyszers_id,
- DialysisIrrigationId: dialysis_irrigation_id,
- DialysisStrainerId: dialysis_strainer_id,
- }
-
- //针对河间咸的
- if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
-
- if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
- solution.DisplaceLiquiPart = 0
- solution.DisplaceLiquiValue = 0
- }
-
- if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
- prescription.DisplaceLiquiPart = 0
- prescription.DisplaceLiquiValue = 0
- }
- }
-
- if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
-
- if solution.PrescribingNumber == 0 {
- solution.PrescribingNumber = 1
- }
- if prescription.PrescribingNumber == 0 {
- prescription.PrescribingNumber = 1
- }
-
- if solution.PrescribingNumber == 0 && id == 14682 {
- solution.PrescribingNumber = 2
- }
-
- if solution.PrescribingNumber == 0 && id == 18560 {
- solution.PrescribingNumber = 2
- }
-
- if prescription.PrescribingNumber == 0 && id == 14682 {
- prescription.PrescribingNumber = 2
- }
-
- if prescription.PrescribingNumber == 0 && id == 18560 {
- prescription.PrescribingNumber = 2
- }
- }
-
- service.SavePrescriptionAndCreateSolution(&solution, &prescription)
-
- if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
-
- monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
-
- if len(monitorList) > 0 {
- var ultrafiltration_rate float64
- totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
-
- ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
- var replacement_rate float64
-
- //乘10 除10是为了保留一位小数
- replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
-
- var firstOpeateTime = monitorList[0].OperateTime
- for _, item := range monitorList {
- //超滤率
- service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
-
- //置换率
- service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
-
- //超滤量
- ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
- service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
-
- //置换量
- displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
- fmt.Println("displacement_quantity----------------------", displacement_quantity)
- service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
-
- }
- }
-
- }
-
- //记录日志
- byterequest, _ := json.Marshal(prescription)
- prescriptionLog := models.XtDialysisPrescriptionLog{
- UserOrgId: prescription.UserOrgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- ErrLog: string(byterequest),
- AdminUserId: adminUserInfo.AdminUser.Id,
- RecordDate: prescription.RecordDate,
- PatientId: prescription.PatientId,
- Source: "手机端新增长期处方",
- Status: 1,
- }
-
- service.CreatePrescriptionLog(prescriptionLog)
-
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 1,
- RecordDate: recordDate.Unix(),
- Sourse: 1,
- PatientId: id,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
- //获取最新1条
- dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
- //更新状态
- service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
-
- //长沙南雅医院,自动生成抗凝剂的临时处方
- if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
- if prescribing_number == 0 {
- prescribing_number = 1
- }
- advice := models.DoctorAdvice{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- GroupNo: 0,
- AdviceType: 2,
- RecordDate: recordDate.Unix(),
- AdviceDate: recordDate.Unix(),
- StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
- AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
- AdviceDesc: "",
- ReminderDate: 0,
- SingleDose: prescription.AnticoagulantZongliang,
- SingleDoseUnit: "iu",
- DrugSpec: 0,
- DrugSpecUnit: "",
- PrescribingNumber: prescribing_number, // 前端传过来的开药数量
- PrescribingNumberUnit: "支",
- DeliveryWay: "静脉注射",
- ExecutionFrequency: "上机前",
- AdviceDoctor: 0,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- IsPrescription: 1,
- ExecutionState: 2,
- StopState: 2,
- IsSettle: 2,
- }
- // 查询排班信息
- schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if schedulePatient.ID > 0 {
- if schedulePatient.ScheduleType == 1 {
- advice.StartTime = recordDate.Unix() + 6.5*60*60
- }
-
- if schedulePatient.ScheduleType == 2 {
- advice.StartTime = recordDate.Unix() + 9*60*60
- }
- }
- // 抗凝剂名称
- switch anticoagulant {
- case 1:
- advice.AdviceName = "无肝素"
- break
- case 2:
- advice.AdviceName = "普通肝素"
- break
- case 3:
- advice.AdviceName = "低分子肝素"
- break
- case 4:
- advice.AdviceName = "阿加曲班"
- break
- case 5:
- advice.AdviceName = "枸橼酸钠"
- break
- case 6:
- advice.AdviceName = "低分子肝素钙"
- break
- case 7:
- advice.AdviceName = "低分子肝素钠"
- break
- case 8:
- advice.AdviceName = "依诺肝素"
- break
- case 9:
- advice.AdviceName = "达肝素"
- break
- case 10:
- advice.AdviceName = "体外抗凝"
- break
- case 11:
- advice.AdviceName = "那曲肝素"
- break
- case 12:
- advice.AdviceName = "无抗凝剂"
- break
- }
- //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
- if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
- advice.AdviceDoctor = appRole.AdminUserId
- }
-
- // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
- advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
-
- if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
-
- advice.AdviceName = "低分子肝素钠注射液"
- // 修改患者临时医嘱里的抗凝剂医嘱
- advice.ID = advicePrescription.ID
- service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
- } else {
- if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
- advice.AdviceName = "低分子肝素钠注射液"
-
- service.CreateDoctorAdvice(&advice)
- }
-
- }
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
- redis := service.RedisClient()
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
-
- }
-
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
-
- //清空长期医嘱的key
- soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
- redis.Set(soulution_key, "", time.Second)
- //查询最近透析准备表里是否存在 透析器 灌流器
-
- keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
- redis.Set(keyTwo, "", time.Second)
-
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
- redis.Set(keyThree, "", time.Second)
-
- keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keyFour, "", time.Second)
- //splitStr := strings.Split(dialysis_dialyszers, ",")
- //
- //splitIrrigation := strings.Split(dialysis_irrigation, ",")
- //
- //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
- //if len(mation)>0{
- // for _, item := range splitStr {
- // for _,it := range mation{
- // if(item == it.SpecificationName){
- //
- // //查询最近一次的透析器
- // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
- //
- // if errcode == gorm.ErrRecordNotFound{
- // //插入数据
- // prepare := models.DialysisBeforePrepare{
- // UserOrgId: adminUserInfo.Org.Id,
- // PatientId: id,
- // RecordDate: recordDate.Unix(),
- // GoodTypeId: it.GoodTypeId,
- // GoodId: it.ID,
- // Count: 1,
- // Ctime: time.Now().Unix(),
- // Creater: adminUserInfo.AdminUser.Id,
- // Status:1,
- //
- // }
- // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
- // fmt.Println("",errcode)
- // }
- // }
- // }
- //
- // }
- //
- // for _, item := range splitIrrigation {
- // for _,it := range mation{
- // if(item == it.SpecificationName){
- // //查询最近一次的透析器
- // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
- // if errcode == gorm.ErrRecordNotFound{
- // //插入数据
- // prepare := models.DialysisBeforePrepare{
- // UserOrgId: adminUserInfo.Org.Id,
- // PatientId: id,
- // RecordDate: recordDate.Unix(),
- // GoodTypeId: it.GoodTypeId,
- // GoodId: it.ID,
- // Count: 1,
- // Ctime: time.Now().Unix(),
- // Creater: adminUserInfo.AdminUser.Id,
- // Status:1,
- //
- // }
- // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
- // fmt.Println(errcode)
- // }
- // }
- // }
- // }
- //}
-
- c.ServeSuccessJSON(map[string]interface{}{
- "solution": &solution,
- "prescription": &prescription,
- })
-
- }
-
- func (c *DialysisAPIController) GetAcceptsAssessment() {
- patient, _ := c.GetInt64("patient", 0)
- adminUserInfo := c.GetMobileAdminUserInfo()
- _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
- c.ServeSuccessJSON(map[string]interface{}{
- "receiveTreatmentAsses": receiveTreatmentAsses,
- })
- }
-
- func (this *DialysisAPIController) PostSignInfo() {
- patientID, _ := this.GetInt64("patient_id")
- recordDateStr := this.GetString("date")
- if patientID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminInfo := this.GetMobileAdminUserInfo()
- err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
-
- if err != nil {
- this.ErrorLog("签名失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "doctor_id": adminInfo.AdminUser.Id,
- })
-
- }
-
- func (this *DialysisAPIController) GetLastMonitorRecord() {
- patientID, _ := this.GetInt64("patient_id")
- adminInfo := this.GetMobileAdminUserInfo()
- record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
- this.ServeSuccessJSON(map[string]interface{}{
- "monitor": record,
- })
-
- }
-
- func (this *DialysisAPIController) GetLastMonitorRecordTody() {
-
- thisTime := time.Now()
- scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theAssessmentDateTime := theStartTime.Unix()
-
- patientID, _ := this.GetInt64("patient_id")
- monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
- adminInfo := this.GetMobileAdminUserInfo()
- record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
- fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
-
- template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
-
- var ultrafiltration_rate float64
- _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
-
- _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
- fmt.Println(evaluation)
- fmt.Println("prescription.ID", prescription.ID)
- if prescription.ID > 0 {
-
- if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
-
- totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
- if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
- record.UltrafiltrationRate = ultrafiltration_rate
-
- }
-
- if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
- ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
- record.UltrafiltrationRate = ultrafiltration_rate
- }
-
- if adminInfo.Org.Id == 10510 {
- record.UltrafiltrationRate = 0
- }
-
- if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
-
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
- record.UltrafiltrationRate = ultrafiltration_rate
- }
-
- if template.TemplateId == 20 || template.TemplateId == 22 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
- record.UltrafiltrationRate = ultrafiltration_rate
- }
-
- // 只针对方济医院
- if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
- ultrafiltration_rate = value
- record.UltrafiltrationRate = ultrafiltration_rate
- }
-
- if template.TemplateId == 41 || template.TemplateId == 47 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
- record.UltrafiltrationRate = ultrafiltration_rate
- }
-
- if template.TemplateId == 43 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
-
- record.UltrafiltrationRate = ultrafiltration_rate
- }
- if template.TemplateId == 46 || template.TemplateId == 54 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
- record.UltrafiltrationRate = ultrafiltration_rate
- }
-
- 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 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
-
- record.UltrafiltrationRate = ultrafiltration_rate
- }
-
- if adminInfo.Org.Id == 10469 {
-
- ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
-
- record.UltrafiltrationRate = ultrafiltration_rate
-
- }
-
- if adminInfo.Org.Id == 10667 {
-
- ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
-
- record.UltrafiltrationRate = ultrafiltration_rate
-
- }
-
- if adminInfo.Org.Id == 10471 {
-
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
- record.UltrafiltrationRate = ultrafiltration_rate / 1000
-
- }
-
- if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
-
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
- record.UltrafiltrationRate = ultrafiltration_rate / 1000
-
- }
-
- if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
-
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
- record.UltrafiltrationRate = ultrafiltration_rate / 1000
- }
-
- if adminInfo.Org.Id == 10721 {
- ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
- record.UltrafiltrationRate = ultrafiltration_rate / 1000
- }
-
- if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
- record.UltrafiltrationRate = 0
- }
- //if template.TemplateId == 47 {
- // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
- // record.UltrafiltrationRate = ultrafiltration_rate
- //}
- }
- }
- // record.UltrafiltrationRate = ultrafiltration_rate
-
- record.UltrafiltrationVolume = 0
-
- 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
- if ultrafiltration_rate > 0 {
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
- record.UltrafiltrationVolume = value
- }
- }
-
- 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
- if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
- ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
- record.UltrafiltrationVolume = ultrafiltration_volume
-
- }
- }
-
- if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
- ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
- record.UltrafiltrationVolume = ultrafiltration_volume
- }
-
- //长沙南雅
- 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 {
-
- if ultrafiltration_rate > 0 {
- ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
-
- record.UltrafiltrationVolume = ultrafiltration_volume
- }
-
- }
-
- if adminInfo.Org.Id == 10471 {
-
- ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
-
- record.UltrafiltrationVolume = ultrafiltration_volume / 1000
- }
-
- if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
-
- ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
-
- record.UltrafiltrationVolume = ultrafiltration_volume / 1000
- }
-
- if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
- ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
-
- record.UltrafiltrationVolume = ultrafiltration_volume / 1000
- }
- //长沙南雅累计血容量自动计算
- //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
- // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
- //}
-
- if template.TemplateId == 47 || template.TemplateId == 54 {
- record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
- }
-
- if adminInfo.Org.Id == 10510 {
- record.UltrafiltrationVolume = 0
- }
-
- if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 {
- if ultrafiltration_rate > 0 {
- ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
- record.UltrafiltrationVolume = ultrafiltration_volume / 1000
- }
-
- }
-
- if adminInfo.Org.Id == 10721 {
- var replacement_rate float64
- var displacement_quantity float64
- totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
- replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
-
- fmt.Println("replacement_rate--------------------------", replacement_rate)
- record.ReplacementRate = replacement_rate
-
- fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
- displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
- record.DisplacementQuantity = displacement_quantity
-
- }
-
- lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "monitor": record,
- "lastMonitorRecordList": lastMonitorRecordList,
- })
-
- }
-
- func (this *DialysisAPIController) ModifyStartDialysisOrder() {
- record_id, _ := this.GetInt64("id")
- nurseID, _ := this.GetInt64("start_nurse")
- puncture_nurse, _ := this.GetInt64("puncture_nurse")
- bedID, _ := this.GetInt64("bed")
- start_time := this.GetString("start_time")
- schedual_type, _ := this.GetInt64("schedual_type")
- washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
- change_nurse, _ := this.GetInt64("change_nurse")
- difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
- new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
- quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
- patient_id, _ := this.GetInt64("patient_id")
- record_date, _ := this.GetInt64("record_date")
- puncture_needle := this.GetString("puncture_needle")
- puncture_way := this.GetString("puncture_way")
- dialysis_dialyszers := this.GetString("dialysis_dialyszers")
- dialysis_irrigation := this.GetString("dialysis_irrigation")
- blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
- nuclein_date_str := this.GetString("nuclein_date_str")
- order_remark := this.GetString("order_remark")
- schedule_remark := this.GetString("schedule_remark")
- catheter_operation := this.GetString("catheter_operation")
- blood_flow_volume := this.GetString("blood_flow_volume")
- blood_drawing, _ := this.GetInt64("blood_drawing")
- dialysis_strainer := this.GetString("dialysis_strainer")
- if record_id == 0 {
- this.ErrorLog("id:%v", record_id)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
- if parseStartDateErr != nil {
- this.ErrorLog("时间解析失败:%v", parseStartDateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetMobileAdminUserInfo()
-
- nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
- if getNurseErr != nil {
- this.ErrorLog("获取护士失败:%v", getNurseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- this.ErrorLog("护士不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
- //if getNurseErr != nil {
- // this.ErrorLog("获取护士失败:%v", getNurseErr)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- //} else if nurse == nil {
- // this.ErrorLog("护士不存在")
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- //}
-
- deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
- if getDeviceNumberErr != nil {
- this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if deviceNumber == nil {
- this.ErrorLog("床位号不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
- //
- //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
- scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
- schedulestartTime := theStartTime.Unix()
- scheduleendTime := theEndTime.Unix()
-
- var theNucleinDate int64
- timeLayoutOne := "2006-01-02"
- if len(nuclein_date_str) > 0 {
- theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- }
- theNucleinDate = theTime.Unix()
- }
-
- //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
-
- schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
-
- if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
-
- if err == gorm.ErrRecordNotFound { //空床位
- // 修改了床位逻辑
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
- if daySchedule.ID > 0 {
- //daySchedule.BedId = bedID
- //daySchedule.PartitionId = deviceNumber.ZoneID
- //daySchedule.ScheduleType = schedual_type
- //daySchedule.UpdatedTime = time.Now().Unix()
- //err := service.UpdateSchedule(&daySchedule)
- xtSchedule := models.Schedule{
- PartitionId: deviceNumber.ZoneID,
- BedId: bedID,
- ScheduleType: schedual_type,
- UpdatedTime: time.Now().Unix(),
- }
- err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- } else if err == nil {
- if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
- if daySchedule.ID > 0 {
- //daySchedule.BedId = bedID
- //daySchedule.PartitionId = deviceNumber.ZoneID
- //
- //daySchedule.ScheduleType = schedual_type
- //daySchedule.UpdatedTime = time.Now().Unix()
- //err := service.UpdateSchedule(&daySchedule)
- xtSchedule := models.Schedule{
- PartitionId: deviceNumber.ZoneID,
- BedId: bedID,
- ScheduleType: schedual_type,
- UpdatedTime: time.Now().Unix(),
- }
- err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
- } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
- return
- }
- } else if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- }
- dialysisRecord := &models.DialysisOrder{
- ID: record_id,
- UserOrgId: adminUserInfo.Org.Id,
- BedID: bedID,
- StartNurse: nurseID,
- StartTime: startDate.Unix(),
- PunctureNurse: puncture_nurse,
- Creator: adminUserInfo.AdminUser.Id,
- Modifier: adminUserInfo.AdminUser.Id,
- WashpipeNurse: washpipe_nurse,
- SchedualType: schedual_type,
- ChangeNurse: change_nurse,
- DifficultPunctureNurse: difficult_puncture_nurse,
- NewFistulaNurse: new_fistula_nurse,
- QualityNurseId: quality_nurse_id,
- PunctureNeedle: puncture_needle,
- PunctureWay: puncture_way,
- DialysisDialyszers: dialysis_dialyszers,
- DialysisIrrigation: dialysis_irrigation,
- BloodAccessId: blood_access_id,
- NucleinDate: theNucleinDate,
- OrderRemark: order_remark,
- ScheduleRemark: schedule_remark,
- CatheterOperation: catheter_operation,
- BloodFlowVolume: blood_flow_volume,
- BloodDrawing: blood_drawing,
- DialysisStrainer: dialysis_strainer,
- }
-
- //修改床位号需要重新消毒
- if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
- service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
-
- //查询第一条监测
- firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
-
- service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
-
- }
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= record_date {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
- //修改床位后重新生成消毒计划
- if adminUserInfo.Org.Id == 10340 {
- //根据床位号获取设备型号
- unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
- //查询使用消毒最后一条消毒记录
- _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
- fmt.Println("err", err)
- if err == gorm.ErrRecordNotFound {
- //查找排班
- scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
- //查询改设备是否有消毒计划
- plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
-
- //根据床位号获取设备id
- addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
-
- //查询病人信息
- patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
- var con = ""
- if patients.IsInfectious == 0 {
- con = ""
- }
- if patients.IsInfectious == 1 {
- con = "无"
- }
- if patients.IsInfectious == 2 {
- con = "有"
- }
-
- if errcode == nil {
- var end_time int64
- end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
- //新增消毒
- information := models.DeviceInformation{
- Date: dialysisRecord.DialysisDate,
- Zone: dialysisRecord.ZoneId,
- Class: dialysisRecord.SchedualType,
- BedNumber: dialysisRecord.BedID,
- PatientId: dialysisRecord.PatientId,
- DialysisMode: scheduleByPatient.ModeId,
- LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
- Disinfection: 1,
- DialysisConcentration: 1,
- DisinfectionStatus: 1,
- Move: 1,
- UserOrgId: dialysisRecord.UserOrgId,
- DisinfectType: plan.Way,
- DisinfectantType: plan.MachineDisinfectant,
- FluidPath: plan.DisinfectanWay, //液路消毒方式
- Disinfectant: plan.Disinfectant,
- Ctime: time.Now().Unix(),
- Status: 1,
- SignName: nurseID,
- EquimentId: addmacher.ID,
- DisinfectionResidue: 2,
- Bed: addmacher.BedNumber,
- StartTime: dialysisRecord.StartTime,
- EndTime: dialysisRecord.EndTime,
- Contagion: con,
- WeightLoss: 0,
- Hyperfiltratio: 0,
- DialysisHour: "",
- MachineRun: 1,
- DisinfecStartime: dialysisRecord.EndTime,
- DisinfecEndtime: end_time,
- }
- err := service.CreateInformationTwo(&information)
- fmt.Println("报错", err)
- }
- }
- }
- order, _ := service.GetLastPatientOrder(record_id)
- service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
- redis := service.RedisClient()
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
-
- //清空key 值
- redis.Set(keyOne, "", time.Second)
- scheduleDateStartOne := startDate.Format("2006-01-02")
- keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- redis.Set(keyTwo, "", time.Second)
-
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
- redis.Set(keyThree, "", time.Second)
- keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
- redis.Set(keyFour, "", time.Second)
-
- keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
- redis.Set(keyFive, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
- redis.Set(keySeven, "", time.Second)
-
- if updateErr != nil {
- this.ErrorLog("修改上机失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if updateErr == nil {
- if tempDialysisRecord.Stage == 2 {
- temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
- fmt.Println(value)
- a, b := math.Modf(value)
- tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
- hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
- minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
- updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
- redis.Set(keyOne, "", time.Second)
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
- //清空key 值
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
- redis.Set(keySeven, "", time.Second)
- redis.Close()
- if updateAssessmentErr != nil {
- utils.ErrorLog("%v", updateAssessmentErr)
- }
- }
- }
-
- _, dialysisRecords := service.FindDialysisOrderById(record_id)
- this.ServeSuccessJSON(map[string]interface{}{
- "dialysis_order": dialysisRecords,
- })
-
- }
- func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
- record_id, _ := c.GetInt64("id")
- nurseID, _ := c.GetInt64("nurse")
- end_time := c.GetString("end_time")
-
- puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
- blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
- catheter := c.GetString("catheter")
- cruor := c.GetString("cruor")
- mission := c.GetString("mission")
- condenser := c.GetString("condenser")
- if record_id <= 0 || nurseID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
- if getNurseErr != nil {
- c.ErrorLog("获取护士失败:%v", getNurseErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- c.ErrorLog("护士不存在")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
- if parseEndDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
-
- //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
- if infor.ID > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= tempDialysisRecords.DialysisDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- dialysisRecord := &models.DialysisOrder{
- ID: record_id,
- UserOrgId: adminUserInfo.Org.Id,
- EndTime: endDate.Unix(),
- FinishNurse: nurseID,
- FinishModifier: adminUserInfo.AdminUser.Id,
- PuncturePointHaematoma: puncture_point_haematoma,
- BloodAccessInternalFistula: blood_access_internal_fistula,
- Catheter: catheter,
- Cruor: cruor,
- Mission: mission,
- Condenser: condenser,
- }
-
- updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
- redis.Set(keySeven, "", time.Second)
- redis.Close()
- if updateErr != nil {
- c.ErrorLog("修改下机失败:%v", updateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if updateErr == nil {
- temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
- a, b := math.Modf(value)
- tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
- hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
- minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
- updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
-
- redis := service.RedisClient()
- keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
- redis.Set(keyTen, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
- redis.Set(keyTwo, "", time.Second)
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
-
- redis.Set(key, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
- redis.Set(keyThree, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
- redis.Set(keySeven, "", time.Second)
- defer redis.Close()
- if updateAssessmentErr != nil {
- utils.ErrorLog("%v", updateAssessmentErr)
- }
- }
-
- _, dialysisRecords := service.FindDialysisOrderById(record_id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "dialysis_order": dialysisRecords,
- })
- }
-
- func (c *DialysisAPIController) GetLongAdvice() {
- patient_id, _ := c.GetInt64("id")
- adminUserInfo := c.GetMobileAdminUserInfo()
- _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
- _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
- is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
-
- prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
- //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
- if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
- c.ServeSuccessJSON(map[string]interface{}{
- "status": "1",
- })
- return
- } else { //开启推送提醒
- //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
- var advice_three []*models.DoctorAdvice
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
-
- nowtime := recordDate.Unix()
- //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
- //fmt.Println("advices232333232323323233232333223233232322332",advices)
- //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
- advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
- advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
- for _, advice := range advices {
- if advice.FrequencyType == 3 {
- t := time.Now()
- week := int(t.Weekday())
- fmt.Println(t.Weekday())
-
- fmt.Println(week)
-
- switch week {
- case 1:
- if strings.Index(advice.WeekDay, "周一") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 2:
- if strings.Index(advice.WeekDay, "周二") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 3:
- if strings.Index(advice.WeekDay, "周三") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 4:
- if strings.Index(advice.WeekDay, "周四") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 5:
- if strings.Index(advice.WeekDay, "周五") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 6:
- if strings.Index(advice.WeekDay, "周六") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 0:
- if strings.Index(advice.WeekDay, "周日") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- }
- }
- }
-
- for _, advice := range advices_two {
- p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
- now := p.Unix()
- dayStr := strconv.FormatInt(advice.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
- advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
-
- for _, ad := range advices {
- advice_three = append(advice_three, ad)
- }
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "status": "2",
- "advices": advices,
- "advices_two": RemoveRepeatedElement(advice_three),
- "is_open_remind": config.IsOpenRemind,
- "his_config_open": hisConfig.IsOpen,
- "is_advice_open": is_advice_open.IsAdviceOpen,
- "prescription_open": prescription_open.IsOpen,
- })
- }
- }
-
- }
-
- func (c *DialysisAPIController) GetLongAdviceOne() {
- patient_id, _ := c.GetInt64("id")
- startTime := c.GetString("schedule_date")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTime int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theStartTime = theTime.Unix()
- }
- adminUserInfo := c.GetMobileAdminUserInfo()
- _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
- _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
- is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
-
- prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
- //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
- if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
- c.ServeSuccessJSON(map[string]interface{}{
- "status": "1",
- })
- return
- } else { //开启推送提醒
- //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
- var advice_three []*models.DoctorAdvice
-
- advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
-
- advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
-
- for _, advice := range advices {
- if advice.FrequencyType == 3 {
- t := time.Now()
- week := int(t.Weekday())
- fmt.Println(t.Weekday())
-
- fmt.Println(week)
-
- switch week {
- case 1:
- if strings.Index(advice.WeekDay, "周一") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 2:
- if strings.Index(advice.WeekDay, "周二") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 3:
- if strings.Index(advice.WeekDay, "周三") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 4:
- if strings.Index(advice.WeekDay, "周四") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 5:
- if strings.Index(advice.WeekDay, "周五") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 6:
- if strings.Index(advice.WeekDay, "周六") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 0:
- if strings.Index(advice.WeekDay, "周日") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- }
- }
- }
-
- for _, advice := range advices_two {
- p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
- now := p.Unix()
- dayStr := strconv.FormatInt(advice.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
- advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
-
- for _, ad := range advices {
- advice_three = append(advice_three, ad)
- }
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "status": "2",
- "advices": advices,
- "advices_two": RemoveRepeatedElement(advice_three),
- "is_open_remind": config.IsOpenRemind,
- "his_config_open": hisConfig.IsOpen,
- "is_advice_open": is_advice_open.IsAdviceOpen,
- "prescription_open": prescription_open.IsOpen,
- })
- }
- }
-
- }
-
- func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
- newArr = make([]*models.DoctorAdvice, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].ID == arr[j].ID {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
-
- patient, _ := c.GetInt64("id", 0)
- groupNo, _ := c.GetInt64("groupno", 0)
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- utils.ErrorLog("%v", dataBody)
-
- timeLayout := "2006-01-02 15:04"
- loc, _ := time.LoadLocation("Local")
-
- timeLayout2 := "2006-01-02"
- loc2, _ := time.LoadLocation("Local")
-
- if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
- utils.ErrorLog("advice_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceType := int64(2)
-
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceDate, _ := dataBody["advice_date"].(string)
- theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
- AdviceDate := theTime.Unix()
- RecordDate := theTime.Unix()
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime, _ := dataBody["start_time"].(string)
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- StartTime := theTime.Unix()
-
- Remark := ""
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark, _ := dataBody["remark"].(string)
- Remark = remark
- }
-
- var advices []*models.GroupAdvice
- if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
- utils.ErrorLog("advices")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceNames := dataBody["advices"].([]interface{})
- for _, adviceNameMap := range adviceNames {
- adviceNameM := adviceNameMap.(map[string]interface{})
- var advice models.GroupAdvice
-
- advice.Remark = Remark
- advice.AdviceType = adviceType
-
- advice.StartTime = StartTime
-
- advice.AdviceDate = AdviceDate
-
- advice.RecordDate = RecordDate
- advice.Status = 1
- advice.CreatedTime = time.Now().Unix()
- advice.UpdatedTime = time.Now().Unix()
- advice.StopState = 2
- advice.ExecutionState = 2
- advice.UserOrgId = adminUserInfo.Org.Id
- advice.PatientId = patient
- advice.AdviceDoctor = adminUserInfo.AdminUser.Id
- advice.IsSettle = 2
- if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceName, _ := adviceNameM["advice_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice.AdviceName = adviceName
-
- if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
-
- if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
- adviceDesc, _ := adviceNameM["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- }
-
- if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
- drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
-
- //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
- // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
- // advice.SingleDose = singleDose
- //}
-
- if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
- //single_dose := int64(adviceNameM["single_dose"].(float64))
- advice.SingleDose = adviceNameM["single_dose"].(float64)
- }
-
- if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
- // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
- // advice.PrescribingNumber = prescribingNumber
- //}
-
- if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
- //single_dose := int64(adviceNameM["single_dose"].(float64))
- advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
- }
-
- if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
- deliveryWay, _ := adviceNameM["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
-
- if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
- frequency_type := int64(adviceNameM["frequency_type"].(float64))
- advice.FrequencyType = frequency_type
- }
-
- if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
- day_count := int64(adviceNameM["day_count"].(float64))
- advice.DayCount = day_count
- }
-
- if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
- week_day, _ := adviceNameM["week_day"].(string)
- advice.WeekDay = week_day
- }
-
- if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
- way := int64(adviceNameM["way"].(float64))
- advice.Way = way
- }
-
- if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
- drug_id := int64(adviceNameM["drug_id"].(float64))
- advice.DrugId = drug_id
- }
-
- if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
- drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
- advice.DrugNameId = drug_name_id
- }
-
- if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
- remark, _ := adviceNameM["remark"].(string)
- advice.Remark = remark
- }
-
- if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
- groupno := int64(adviceNameM["groupno"].(float64))
- advice.GroupNo = groupno
- }
-
- if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
- template_id, _ := adviceNameM["template_id"].(string)
- advice.TemplateId = template_id
- }
-
- if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
- children := adviceNameM["child"].([]interface{})
- if len(children) > 0 {
- for _, childrenMap := range children {
- childMap := childrenMap.(map[string]interface{})
- var child models.GroupAdvice
- child.Remark = Remark
- child.AdviceType = adviceType
- child.StartTime = StartTime
- child.AdviceDate = AdviceDate
- child.RecordDate = RecordDate
- child.Status = 1
- child.CreatedTime = time.Now().Unix()
- child.UpdatedTime = time.Now().Unix()
- child.StopState = 2
- child.ExecutionState = 2
- child.UserOrgId = adminUserInfo.Org.Id
- child.PatientId = patient
- child.AdviceDoctor = adminUserInfo.AdminUser.Id
- child.IsSettle = 1
- if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
- utils.ErrorLog("child advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- childAdviceName, _ := childMap["advice_name"].(string)
- if len(childAdviceName) == 0 {
- utils.ErrorLog("len(child advice_name) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- child.AdviceName = childAdviceName
-
- if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
- childAdviceDesc, _ := childMap["advice_desc"].(string)
- child.AdviceDesc = childAdviceDesc
- }
-
- if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
- childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
- child.DrugSpec = childDrugSpec
- }
-
- if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
- childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
- child.DrugSpecUnit = childDrugSpecUnit
- }
-
- if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
- child.SingleDose = childMap["single_dose"].(float64)
- }
-
- if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
- childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
- child.SingleDoseUnit = childSingleDoseUnit
- }
-
- if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
- child.PrescribingNumber = childMap["prescribing_number"].(float64)
- }
-
- if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
- childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
- child.PrescribingNumberUnit = childPrescribingNumberUnit
- }
-
- if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
- groupno := int64(childMap["groupno"].(float64))
- advice.GroupNo = groupno
- }
-
- if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
- remark, _ := childMap["remark"].(string)
- child.Remark = remark
- }
-
- child.DeliveryWay = advice.DeliveryWay
- child.ExecutionFrequency = advice.ExecutionFrequency
- advice.Children = append(advice.Children, &child)
- }
- }
- }
-
- temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
- if temp_advice.ID == 0 {
- advices = append(advices, &advice)
- }
- }
-
- if len(advices) > 0 {
-
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 4,
- RecordDate: AdviceDate,
- Sourse: 1,
- PatientId: patient,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
-
- if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
- list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
- for _, item := range advices {
- byterequest, _ := json.Marshal(item)
- adviceLog := models.XtDoctorAdviceLog{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: patient,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 1,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "手机端医嘱推送",
- RecordDate: item.AdviceDate,
- }
-
- service.CreateDoctorAdviceLog(adviceLog)
- }
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
-
- keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- defer redis.Close()
- redis.Set(keyThree, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advices": list,
- })
- } else {
- list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
- for _, item := range advices {
- byterequest, _ := json.Marshal(item)
- adviceLog := models.XtDoctorAdviceLog{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: patient,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 1,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "手机端医嘱推送",
- RecordDate: item.AdviceDate,
- }
-
- service.CreateDoctorAdviceLog(adviceLog)
- }
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
-
- keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- defer redis.Close()
- redis.Set(keyThree, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advices": list,
- })
- }
-
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
-
- }
-
- return
-
- }
-
- func (c *DialysisAPIController) UploadDryWeight() {
- patient_id, _ := c.GetInt64("id")
- dry_weight, _ := c.GetFloat("dry_weight")
- doctor_id, _ := c.GetInt64("doctor_id")
- remark := c.GetString("remark")
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
- if err == gorm.ErrRecordNotFound {
- dryWeight := &models.SgjPatientDryweight{
- PatientId: patient_id,
- DryWeight: dry_weight,
- Remakes: remark,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Creator: doctor_id,
- Status: 1,
- UserOrgId: adminUserInfo.Org.Id,
- AdjustedValue: "/",
- UserId: adminUserInfo.AdminUser.Id,
- }
- createErr := service.CreatePatientWeightAdjust(dryWeight)
- redis := service.RedisClient()
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
- redis.Set(keyOne, "", time.Second)
- loc, _ := time.LoadLocation("Local")
- nowTime := time.Now()
- nowDay := nowTime.Format("2006-01-02")
- dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
- redis.Set(keyTwo, "", time.Second)
- redis.Close()
- if createErr == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- "weight": dryWeight,
- })
- }
-
- } else {
- dryWeight := &models.SgjPatientDryweight{
- PatientId: patient_id,
- DryWeight: dry_weight,
- Remakes: remark,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Creator: doctor_id,
- Status: 1,
- UserOrgId: adminUserInfo.Org.Id,
- AdjustedValue: "/",
- UserId: adminUserInfo.AdminUser.Id,
- }
- var value float64
- value = dry_weight - weightAdjust.DryWeight
-
- if value < 0 {
- dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
- } else if value == 0 {
- dryWeight.AdjustedValue = "/"
- } else if value > 0 {
- dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
- }
-
- createErr := service.CreatePatientWeightAdjust(dryWeight)
-
- //康桥
- if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
-
- dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
-
- if beforAssesment.ID > 0 {
-
- service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
-
- var dewater_amount float64
-
- dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
-
- service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
- //清空key 值
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
- }
-
- }
- redis := service.RedisClient()
- loc, _ := time.LoadLocation("Local")
- nowTime := time.Now()
- nowDay := nowTime.Format("2006-01-02")
- dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
- redis.Set(keyOne, "", time.Second)
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
- redis.Set(keyTwo, "", time.Second)
- redis.Close()
- if createErr == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- "weight": dryWeight,
- })
- }
- }
-
- }
-
- func (c *DialysisAPIController) GetSolution() {
- patient_id, _ := c.GetInt64("patient_id")
- mode_id, _ := c.GetInt64("mode_id")
- adminUserInfo := c.GetMobileAdminUserInfo()
- solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
- prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
- system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
- dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "solution": solution,
- "prescription": prescription,
- "system_prescription": system_prescription,
- "dialysisPrescription": dialysisPrescription,
- })
-
- }
-
- func (c *DialysisAPIController) GetSchedule() {
- schedual_type, _ := c.GetInt64("schedual_type")
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- scheduleTime, _ := c.GetInt64("record_date")
- deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
- list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
- c.ServeSuccessJSON(map[string]interface{}{
- "number": deviceNumber,
- "list": list,
- })
-
- }
-
- func (c *DialysisAPIController) GetPatientId() {
-
- id, _ := c.GetInt64("id")
- //orgid := c.GetMobileAdminUserInfo().Org.Id
- patientId, _ := service.GetPatientId(id)
- //获取该患者的所有传染病
- list, _ := service.GetPatientInfectious(id)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patientId,
- "infectioulist": list,
- })
- }
-
- func (this *DialysisAPIController) GetDialysisSchedule() {
- schedualDate := this.GetString("date")
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
- if parseDateErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminInfo := this.GetMobileAdminUserInfo()
- orgID := adminInfo.Org.Id
- redis := service.RedisClient()
- defer redis.Close()
- key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
- scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
- if len(scheduals) > 0 {
- //缓存数据
- scheduals_json, err := json.Marshal(scheduals)
- if err == nil {
- redis.Set(key, scheduals_json, time.Second*30)
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduals": scheduals,
- })
-
- }
-
- func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
- change_type, _ := this.GetInt64("type", 0)
- record_date := this.GetString("record_time")
- patient_id, _ := this.GetInt64("patient_id", 0)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
- record_time := theAdviceRecordTime.Unix()
- adminUserInfo := this.GetMobileAdminUserInfo()
- advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
- if err == nil {
- if len(advices) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
- return
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "advices": advices,
- "schedule": sch,
- })
- return
- }
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *DialysisAPIController) CreateConsumables() {
- record_date := c.GetString("record_time")
- patient_id, _ := c.GetInt64("patient_id", 0)
- active, _ := c.GetInt64("active")
- adminUser := c.GetMobileAdminUserInfo()
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
- record_time := theRecordTime.Unix()
-
- // 查询信息规挡的设置天数
- orgid := c.GetMobileAdminUserInfo().Org.Id
- infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
- if infor.ID > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= record_time {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
-
- var beforePrepares []*models.DialysisBeforePrepareGoods
- var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
- var dialysisBefor []*models.DialysisBeforePrepare
- if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
- goods, _ := dataBody["goods"].([]interface{})
-
- if len(goods) > 0 {
- for _, item := range goods {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
- commdity_code := items["commdity_code"].(string)
- fmt.Println("commdity", commdity_code)
-
- prepareGoods := &models.DialysisBeforePrepareGoods{
- GoodTypeId: good_type_id,
- GoodId: good_id,
- Count: count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- beforePrepares = append(beforePrepares, prepareGoods)
-
- newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
- GoodTypeId: good_type_id,
- GoodId: good_id,
- Count: count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
-
- prepare := &models.DialysisBeforePrepare{
- GoodTypeId: good_type_id,
- GoodId: good_id,
- Count: count,
- PatientId: patient_id,
- RecordDate: record_time,
- UserOrgId: adminUser.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- CommdityCode: commdity_code,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- dialysisBefor = append(dialysisBefor, prepare)
-
- }
- }
-
- //查询是否有库存
- for _, item := range dialysisBefor {
- _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
-
- if err == gorm.ErrRecordNotFound {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
- if err != nil {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
- }
-
- fmt.Println("active-----------------------", active)
- fmt.Println("len(goods)-----------------------", len(goods))
- //新增
- if active == 1 && len(goods) > 0 {
- for _, item := range dialysisBefor {
- dialyPrepareOne := models.DialysisBeforePrepare{
- GoodTypeId: item.GoodTypeId,
- GoodId: item.GoodId,
- PatientId: item.PatientId,
- RecordDate: item.RecordDate,
- UserOrgId: item.UserOrgId,
- Count: item.Count,
- Ctime: time.Now().Unix(),
- Creater: item.Creater,
- CommdityCode: item.CommdityCode,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //先清除再插入
- service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
- err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
-
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
-
- //更新库存
- goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
-
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- "message": "2",
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- if len(beforePrepares) > 0 && active == 2 {
-
- for _, item := range beforePrepares {
-
- //1.查看该患者该耗材型号最后一次出库数量
- goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
-
- //判断当前出库数量和最后一次出库数量的大小
- //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
-
- if item.Count <= goodInfo.Count {
- //退库
- err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
-
- //查询今日出库数据
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
-
- for _, it := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: it.OrgId,
- PatientId: patient_id,
- RecordDate: it.RecordTime,
- GoodId: it.GoodId,
- GoodTypeId: it.GoodTypeId,
- Count: it.Count,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //删除准备表数据
- service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
-
- service.CreateDialysisBeforePrepareOne(&prepare)
-
- }
- }
-
- var last_total int64
-
- //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
- if item.Count >= goodInfo.Count {
-
- //查询当前批次当前耗材最后一条出库数据
- lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
-
- //计算当前出库和最后一次出库数据相差数据
- last_total = item.Count - lastOutInfo.Count
-
- //查询该批次剩余库存
- lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
-
- //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
- if lastInfo.StockCount >= last_total {
-
- err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
-
- //查询今日出库数据
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
-
- for _, it := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: it.OrgId,
- PatientId: patient_id,
- RecordDate: it.RecordTime,
- GoodId: it.GoodId,
- GoodTypeId: it.GoodTypeId,
- Count: it.Count,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //删除准备表数据
- service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
-
- service.CreateDialysisBeforePrepareOne(&prepare)
- //查询默认仓库
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
-
- goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- }
- }
-
- //如果库存不够,则出库到下一个批次
- if lastInfo.StockCount < last_total {
-
- err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
- //查询今日出库数据
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
-
- for _, it := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: it.OrgId,
- PatientId: patient_id,
- RecordDate: it.RecordTime,
- GoodId: it.GoodId,
- GoodTypeId: it.GoodTypeId,
- Count: it.Count,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //删除准备表数据
- service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
-
- service.CreateDialysisBeforePrepareOne(&prepare)
- //查询默认仓库
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
-
- goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- }
- if err != nil {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
- }
-
- }
-
- if err != nil {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
- }
-
- }
- }
-
- var errs error
-
- if errs == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- "message": "2",
- "good_name": "",
- "specification_name": "",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *DialysisAPIController) CreateStockOutInfo() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- record_date := c.GetString("record_time")
-
- if patient_id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminInfo := c.GetMobileAdminUserInfo()
-
- creator := c.GetMobileAdminUserInfo().AdminUser.Id
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
- record_time := theRecordTime.Unix()
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= record_time {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- //创建步骤表
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminInfo.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 11,
- RecordDate: record_time,
- Sourse: 1,
- PatientId: patient_id,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
- consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
-
- _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
-
- //去重
- consumables = RemoveRepeatedGood(consumables)
-
- if adminInfo.Org.Id == 9919 {
- houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- //查询是否有库存
- for _, item := range consumables {
- warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
-
- if item.Count > warehouse.Count {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.UserOrgId,
- Errcode: "自动出库库存不足",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: warehouse.ID,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
-
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
- }
-
- //查询是否有出库单
- out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
- if err == gorm.ErrRecordNotFound {
- //没有记录,则创建出库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- creater := adminInfo.AdminUser.Id
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: time.Now().Unix(),
- OrgId: adminInfo.Org.Id,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: record_time,
- Dealer: 0,
- Manufacturer: 0,
- Type: 1,
- IsSys: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- err := service.AddSigleWarehouseOut(&warehouseOut)
- if err != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "创建出库单失败",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- utils.TraceLog("创建出库单失败 err = %v", err)
-
- } else {
-
- for _, item := range consumables {
- //出库
- err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
-
- //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
-
- if err == nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库接口报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- utils.TraceLog("创建出库单失败 err = %v", err)
- }
-
- //查询
-
- //出库数量相加
- errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.UserOrgId,
- Errcode: "创建剩余库存字段报错",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- }
-
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
- if len(list) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- for _, item := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: adminInfo.Org.Id,
- PatientId: patient_id,
- RecordDate: record_time,
- GoodId: item.GoodId,
- GoodTypeId: item.GoodTypeId,
- Count: item.Count,
- Creater: adminInfo.AdminUser.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //清空准备表数据
- err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
- if err != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库清空准备表数据报错",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- errs := service.CreateDialysisBeforePrepareOne(&prepare)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库创建准备表数据报错",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
- if errcodes != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库基础库插入数据",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- if errsss != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库剩余库存更新数据",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- }
- }
- //
- } else if err == nil {
- for _, item := range consumables {
- //出库
- err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
- //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
- if err != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库接口报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- //出库数量相加
- errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
- if errss != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.UserOrgId,
- Errcode: "创建剩余库存字段报错",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Count: 0,
- StockCount: 0,
- Creater: item.Creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
- if len(list) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- for _, item := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: adminInfo.Org.Id,
- PatientId: patient_id,
- RecordDate: record_time,
- GoodId: item.GoodId,
- GoodTypeId: item.GoodTypeId,
- Count: item.Count,
- Creater: adminInfo.AdminUser.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- //清空准备表数据
- errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库清空准备表数据报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
- if errcodes != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库创建准备表数据报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
- if errcodes != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库基础库插入数据报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- creater := c.GetMobileAdminUserInfo().AdminUser.Id
- if errss != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库剩余库存更新数据",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- }
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- "message": "2",
- "good_name": "",
- "specification_name": "",
- })
- return
- }
- if record.IsOpen == 1 {
- houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- //查询是否有库存
- for _, item := range consumables {
- warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
-
- if item.Count > warehouse.Count {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.UserOrgId,
- Errcode: "自动出库库存不足",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: warehouse.ID,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
-
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
- }
-
- //查询是否有出库单
- out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
- if err == gorm.ErrRecordNotFound {
- //没有记录,则创建出库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- creater := adminInfo.AdminUser.Id
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: time.Now().Unix(),
- OrgId: adminInfo.Org.Id,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: record_time,
- Dealer: 0,
- Manufacturer: 0,
- Type: 1,
- IsSys: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- err := service.AddSigleWarehouseOut(&warehouseOut)
- if err != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "创建出库单失败",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- utils.TraceLog("创建出库单失败 err = %v", err)
-
- } else {
-
- for _, item := range consumables {
- //出库
- err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
-
- //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
-
- if err == nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库接口报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- utils.TraceLog("创建出库单失败 err = %v", err)
- }
-
- //查询
-
- //出库数量相加
- errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.UserOrgId,
- Errcode: "创建剩余库存字段报错",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- }
-
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
- if len(list) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- for _, item := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: adminInfo.Org.Id,
- PatientId: patient_id,
- RecordDate: record_time,
- GoodId: item.GoodId,
- GoodTypeId: item.GoodTypeId,
- Count: item.Count,
- Creater: adminInfo.AdminUser.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //清空准备表数据
- err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
- if err != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库清空准备表数据报错",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- errs := service.CreateDialysisBeforePrepareOne(&prepare)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库创建准备表数据报错",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
- if errcodes != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库基础库插入数据",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- if errsss != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库剩余库存更新数据",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- }
- }
- //
- } else if err == nil {
- for _, item := range consumables {
- //出库
- err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
- //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
- if err != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库接口报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- //出库数量相加
- errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
- if errss != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.UserOrgId,
- Errcode: "创建剩余库存字段报错",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Count: 0,
- StockCount: 0,
- Creater: item.Creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
- if len(list) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- for _, item := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: adminInfo.Org.Id,
- PatientId: patient_id,
- RecordDate: record_time,
- GoodId: item.GoodId,
- GoodTypeId: item.GoodTypeId,
- Count: item.Count,
- Creater: adminInfo.AdminUser.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- //清空准备表数据
- errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库清空准备表数据报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
- if errcodes != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库创建准备表数据报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
- if errcodes != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库基础库插入数据报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- creater := c.GetMobileAdminUserInfo().AdminUser.Id
- if errss != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库剩余库存更新数据",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- }
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- "message": "2",
- "good_name": "",
- "specification_name": "",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
- return
- }
-
- }
-
- func (c *DialysisAPIController) EditConsumables() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- record_date := c.GetString("record_time")
-
- if patient_id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminInfo := c.GetMobileAdminUserInfo()
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
- record_time := theRecordTime.Unix()
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= record_time {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- var beforePrepares []*models.DialysisBeforePrepareGoods
-
- var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
-
- var cancelbefor []*models.DialysisBeforePrepareGoods
- var outbefor []*models.DialysisBeforePrepareGoods
-
- //判断是否开启自动出库
- _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
-
- if record.IsOpen == 1 {
-
- if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
-
- goods, _ := dataBody["goods"].([]interface{})
-
- if len(goods) > 0 {
- for _, item := range goods {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- commdity_code := items["commdity_code"].(string)
-
- fmt.Println(commdity_code)
-
- prepareGoods := &models.DialysisBeforePrepareGoods{
- GoodTypeId: good_type_id,
- GoodId: good_id,
- Count: count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- beforePrepares = append(beforePrepares, prepareGoods)
-
- newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
- GoodTypeId: good_type_id,
- GoodId: good_id,
- Count: count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
- }
-
- for _, item := range beforePrepares {
-
- //1.查看该患者该耗材型号最后一次出库数量
- goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
- //判断当前出库数量和最后一次出库数量的大小
- //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
- if item.Count < goodInfo.Count {
- cancelbefor = append(cancelbefor, item)
- }
-
- //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
- if item.Count > goodInfo.Count {
-
- outbefor = append(outbefor, item)
- }
-
- //处理编辑耗材新增不了的问题
- if goodInfo.Count == item.Count {
- lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
- service.UpdateLastAutoCount(lastCount.ID, item.Count)
- }
-
- }
-
- if len(cancelbefor) > 0 {
- //退库
- for _, item := range cancelbefor {
- warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
- creater := adminInfo.AdminUser.Id
-
- //查询该患者当天已经出库的耗材信息
- warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
-
- var delete_count int64 = 0
-
- delete_count = warehouseOutInfos.Count - item.Count
-
- //增加库存数量
- service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
-
- //减少实际出库库存数量
- service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
-
- // 删除出库完成后,要增加对应批次的库存数量
-
- service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
-
- houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
-
- //更新剩余库存
- goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodListOne {
- flush_count += it.StockCount
- }
- service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
-
- //查询剩余库存
- goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
- var sum_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- }
-
- // 在出库记录表里记录退库详情
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- OrgId: adminInfo.Org.Id,
- Type: 1,
- IsSys: 1,
- SysRecordTime: record_time,
- GoodTypeId: item.GoodTypeId,
- GoodId: item.GoodId,
- PatientId: patient_id,
- ConsumableType: 2,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- OverCount: sum_count,
- }
- warehouseOutInfo.Count = item.Count
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.Dealer = stockInInfo.Dealer
- warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
- warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
- warehouseOutInfo.ProductDate = stockInInfo.ProductDate
- warehouseOutInfo.Number = warehouseOutInfos.Number
- warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
- warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
- //查找当天是否存在出库记录
- _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
-
- if errcod == gorm.ErrRecordNotFound {
- service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- //插入详情明细表
- stockFlow := models.VmStockFlow{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: item.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: item.Count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: record_time,
- UserOrgId: adminInfo.Org.Id,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
- if errflow == gorm.ErrRecordNotFound {
- //创建流水表
- err := service.CreateStockFlowOne(stockFlow)
- fmt.Println("err", err)
- } else if errflow == nil {
- //插入详情明细表
- stockFlow := models.VmStockFlow{
- ID: exsit.ID,
- WarehousingId: warehouseOutInfos.WarehouseInfotId,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: item.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: exsit.Count - delete_count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: record_time,
- UserOrgId: adminInfo.Org.Id,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
- }
-
- } else if errcod == nil {
- service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
-
- //查询剩余库存
- goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
- var sum_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- }
-
- //创建退库单,生成退库数据
- houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
-
- operation_time := time.Now().Unix()
- creater := adminInfo.AdminUser.Id
- //创建退库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: adminInfo.Org.Id,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- ReturnTime: record_time,
- Type: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
- if msgerrkonde == gorm.ErrRecordNotFound {
- service.AddSigleCancelStock(&cancelStock)
- }
- cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
-
- //查询是否有出库
- info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
-
- manufacturer, _ := service.GetManufactureById(info.Manufacturer)
- deaerler, _ := service.GetDealerById(info.Dealer)
-
- if info.ID > 0 {
- cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
- cancelStockInfo := models.CancelStockInfo{
- GoodId: item.GoodId,
- CancelStockId: cancel.ID,
- GoodTypeId: good.GoodTypeId,
- Count: delete_count,
- Price: info.Price,
- Total: 0,
- ProductDate: info.ProductDate,
- ExpiryDate: info.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: adminInfo.Org.Id,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: info.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: info.WarehouseInfotId,
- PatientId: info.PatientId,
- RecordDate: info.SysRecordTime,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
-
- //退库数量增加
- service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
-
- //查询剩余库存
- goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
- var over_count int64
- for _, it := range goodList {
- over_count += it.StockCount
- }
-
- flow := models.VmStockFlow{
- WarehousingId: info.WarehouseInfotId,
- GoodId: item.GoodId,
- Number: info.Number,
- LicenseNumber: info.LicenseNumber,
- Count: delete_count,
- UserOrgId: adminInfo.Org.Id,
- PatientId: patient_id,
- SystemTime: info.SysRecordTime,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: info.WarehouseOutId,
- WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: adminInfo.AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: record_time,
- Mtime: 0,
- Price: info.Price,
- WarehousingDetailId: info.WarehouseInfotId,
- WarehouseOutDetailId: info.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: info.ProductDate,
- ExpireDate: info.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: over_count,
- }
- service.CreateStockFlowOne(flow)
-
- }
- }
-
- //更改自动出库的表格
- details := models.BloodAutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient_id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: record_time,
- OrgId: adminInfo.Org.Id,
- GoodId: item.GoodId,
- GoodTypeId: item.GoodTypeId,
- Count: item.Count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //查询当天耗材是否已经存在数据
- _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
-
- if errcode == gorm.ErrRecordNotFound {
- service.CreateAutoReduceRecord(&details)
-
- } else if errcode == nil {
- service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
- service.CreateAutoReduceRecord(&details)
-
- }
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
-
- }
- }
-
- if len(outbefor) > 0 {
- //出库
- for _, item := range outbefor {
-
- var last_total int64
- //1.查看该患者该耗材型号最后一次出库数量
- goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
- //计算当前出库和最后一次出库数据相差数据
- last_total = item.Count - goodInfoOne.Count
-
- //查询该耗材的总库存
- wareinfo, _ := service.GetStockGoodCount(item.GoodId)
-
- // 如果库存差大于剩余库存则提示库存不足
- if last_total > wareinfo.StockCount {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- } else {
-
- out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
- houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- if err == gorm.ErrRecordNotFound {
- //没有记录,则创建出库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: time.Now().Unix(),
- OrgId: adminInfo.Org.Id,
- Creater: adminInfo.AdminUser.Id,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: record_time,
- Dealer: 0,
- Manufacturer: 0,
- Type: 1,
- IsSys: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- service.AddSigleWarehouseOut(&warehouseOut)
-
- }
- //出库
- //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
- //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- //1.查看该患者该耗材型号最后一次出库数量
- goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
-
- prepare := models.DialysisBeforePrepare{
- UserOrgId: adminInfo.Org.Id,
- PatientId: patient_id,
- RecordDate: record_time,
- GoodId: item.GoodId,
- GoodTypeId: item.GoodTypeId,
- Count: item.Count - goodInfoTwo.Count,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Creater: adminInfo.AdminUser.Id,
- Modifier: adminInfo.AdminUser.Id,
- Status: 1,
- CommdityCode: "",
- NewCount: 0,
- ProjectId: 0,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
- //增加出库数量
- service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
- //剩余库存
-
- goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- }
- }
- }
-
- //查询今日出库数据
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
-
- for _, it := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: it.OrgId,
- PatientId: patient_id,
- RecordDate: it.RecordTime,
- GoodId: it.GoodId,
- GoodTypeId: it.GoodTypeId,
- Count: it.Count,
- Ctime: time.Now().Unix(),
- Creater: adminInfo.AdminUser.Id,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- ProjectId: it.ProjectId,
- }
- //删除准备表数据
- service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
-
- service.CreateDialysisBeforePrepareOne(&prepare)
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
-
- goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
-
- }
- }
- }
-
- //更新自动出库的地方
- var errs error
- if errs == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "修改成功",
- "message": "2",
- "good_name": "",
- "specification_name": "",
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- }
-
- func (c *DialysisAPIController) GetDialysisGoods() {
- schedualDate := c.GetString("schedule_date")
- schedule_type, _ := c.GetInt64("schedule_type")
- partition_id, _ := c.GetInt64("partition_id")
- page, _ := c.GetInt("page")
- patient_id, _ := c.GetInt64("patient_id")
-
- schedualEndDate := int64(0)
-
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
- if parseDateErr != nil && len(schedualDate) != 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
- if parseDateErr != nil && len(schedualDate) != 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedualEndDate = endDate.Unix()
-
- adminUser := c.GetMobileAdminUserInfo()
-
- _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
-
- goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
-
- project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
-
- _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
-
- outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
-
- settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
-
- //获取当天该病人的透析处方
- prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
- good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
- if err == gorm.ErrRecordNotFound {
- dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
- warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
- if patient_id != 0 {
- for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
- goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
-
- lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
-
- //获取患者总的出库数据
- item.LastAutomaticReduceDetail = goodUser
- item.LastDialysisBeforePrepare = lastGoodUserDetial
- item.Project = project
-
- for _, it := range item.AutomaticReduceDetail {
- var total int64
- auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
- for _, its := range auto {
- total += its.Count
- }
- it.Count = total
- }
- }
-
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "dialysis_goods": dialysisGoods,
- "good_type": goodTypes,
- "total": total,
- "prescribe": prescribe,
- "good_info": good_info,
- "warehouseOutList": warehouseOutList,
- "config": config,
- "outConfig": outConfig,
- "settleConfig": settleConfig,
- })
- return
-
- } else if err == nil {
- //获取当天排班的每个患者的库存使用情况
- dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
- //获取患者总的出库数据
- warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
- if patient_id != 0 {
- for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
- goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
- lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
- item.Project = project
- item.LastAutomaticReduceDetail = goodUser
- item.LastDialysisBeforePrepare = lastGoodUserDetial
- for _, it := range item.AutomaticReduceDetail {
- var total int64
- auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
- for _, its := range auto {
- total += its.Count
- }
- it.Count = total
- }
- }
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "dialysis_goods": dialysisGoods,
- "good_type": goodTypes,
- "total": total,
- "prescribe": prescribe,
- "good_info": good_info,
- "project": project,
- "warehouseOutList": warehouseOutList,
- "config": config,
- "outConfig": outConfig,
- "settleConfig": settleConfig,
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- } else if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
-
- }
- func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var theStartTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- }
- theStartTime = theTime.Unix()
- }
- var theEndtTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- }
- theEndtTime = theTime.Unix()
- }
-
- adminUser := c.GetMobileAdminUserInfo()
- outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
- stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "stock_out": outInfo,
- "stockCount": stockCount,
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
- func (c *DialysisAPIController) GetStockInGoodInfo() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- record_time := c.GetString("record_time")
- adminUser := c.GetMobileAdminUserInfo()
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
- if parseDateErr != nil && len(record_time) != 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
- good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
-
- goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
- lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
-
- project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
-
- //获取今日患者的透析处方参数
- prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
-
- outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
-
- _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
- c.ServeSuccessJSON(map[string]interface{}{
- "good_type": goodTypes,
- "good_user": goodUser,
- "good_info": good_info,
- "last_good_user": lastGoodUserDetial,
- "project": project,
- "prescription": prescribe,
- "outInfo": outInfo,
- "configs": configs,
- })
- return
-
- }
-
- func (c *DialysisAPIController) CreateOtherStockOutInfo() {
-
- patient_id, _ := c.GetInt64("patient_id", 0)
- record_date := c.GetString("record_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
- record_time := theRecordTime.Unix()
- adminInfo := c.GetMobileAdminUserInfo()
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
-
- var beforePrepares []*models.DialysisBeforePrepareGoods
-
- var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
-
- if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
- goods, _ := dataBody["goods"].([]interface{})
- if len(goods) > 0 {
- for _, item := range goods {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
- utils.ErrorLog("project_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- project_id := int64(items["project_id"].(float64))
-
- new_count := int64(items["new_count"].(float64))
- old_count := int64(items["old_count"].(float64))
-
- prepare := &models.DialysisBeforePrepareGoods{
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- ProjectId: project_id,
- StorehouseId: houseConfig.StorehouseOutInfo,
- NewCount: new_count,
- OldCount: old_count,
- }
-
- beforePrepares = append(beforePrepares, prepare)
-
- newPrepare := &models.NewDialysisBeforePrepareGoods{
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- ProjectId: project_id,
- StorehouseId: houseConfig.StorehouseOutInfo,
- NewCount: new_count,
- OldCount: old_count,
- }
-
- newBeforePrepares = append(newBeforePrepares, newPrepare)
-
- }
- }
- }
-
- //查询是否有库存
-
- for _, item := range beforePrepares {
-
- if item.NewCount > 0 {
- storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
-
- if item.Count > warehouse.Count {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
- }
-
- }
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= record_time {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- //出库逻辑
- err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
-
- }
-
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminInfo.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 11,
- RecordDate: record_time,
- Sourse: 1,
- PatientId: patient_id,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
-
- //查询当天出库的数据
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
-
- for _, item := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: item.OrgId,
- PatientId: item.PatientId,
- RecordDate: item.RecordTime,
- GoodId: item.GoodId,
- GoodTypeId: item.GoodTypeId,
- Count: item.Count,
- Creater: adminInfo.AdminUser.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- ProjectId: item.ProjectId,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //清空准备表的数据
- err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
- //插入准备表数据
- service.CreateDialysisBeforePrepareOne(&prepare)
-
- //查询默认仓库
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
-
- ////更新剩余库存
-
- goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "手动出库更新剩余出库失败",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: adminInfo.AdminUser.Id,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- }
-
- //更新自动出库的地方
- var errs error
- if errs == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "修改成功",
- "message": "2",
- "good_name": "",
- "specification_name": "",
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
-
- func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
- newArr = make([]*models.DialysisBeforePrepare, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func (c *DialysisAPIController) GetAllDrug() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- adminInfo := c.GetMobileAdminUserInfo()
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
- privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
- drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
- privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "base_drug_config": drugStockConfig,
- "private_drug_config": privateDrugConfig,
- "base_drug_list": drugList,
- "private_drug_list": privateDrugList,
- })
-
- }
-
- func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
- newArr = make([]*models.DialysisBeforePrepare, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].GoodId == arr[j].GoodId {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func (c *DialysisAPIController) GetDepartment() {
- adminInfo := c.GetMobileAdminUserInfo()
- departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "departments": departments,
- })
- } else {
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
-
- }
-
- func (c *DialysisAPIController) GetMobilePrintStockGood() {
-
- types, _ := c.GetInt("type", 0)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- orgId := c.GetMobileAdminUserInfo().Org.Id
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
- stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "type": types,
- "stockTotal": stockTotal,
- })
- }
- }
-
- func (c *DialysisAPIController) GetPrescriptionList() {
-
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- schedule_type, _ := c.GetInt64("schedule_type")
- partion_id, _ := c.GetInt64("partion_id")
- orgId := c.GetMobileAdminUserInfo().Org.Id
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
-
- fmt.Println("schedulelist22222222", schedulelist)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": schedulelist,
- })
- return
-
- }
-
- func (c *DialysisAPIController) BatchDeleteMonitor() {
-
- ids := c.GetString("ids")
- //patient_id, _ := c.GetInt64("patient_id")
- //monitoring_date, _ := c.GetInt64("monitoring_date")
- idArray := strings.Split(ids, ",")
- err := service.BatchDeleteMonitor(idArray)
- fmt.Print("err", err)
- //orgid := c.GetMobileAdminUserInfo().Org.Id
- //redis := service.RedisClient()
- //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
- //redis.Set(key, "", time.Second)
- //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
- //redis.Set(keyOne, "", time.Second)
- //fmt.Println("keyo呢32332322332332232332",keyOne)
- //redis.Close()
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "批量删除成功",
- })
- return
- }
-
- func (c *DialysisAPIController) GetPatientDialysisRecordList() {
-
- id, _ := c.GetInt64("id")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- //start_time := time.Now().Format("2006-01-02")
-
- start_time := c.GetString("start_time")
-
- end_time := c.GetString("end_time")
-
- var startdateunix int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startdateunix = theTime.Unix()
- }
- var enddateunix int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- enddateunix = theTime.Unix()
- }
-
- //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
-
- //nowTime := time.Now()
-
- //endTime := nowTime.AddDate(-30, 0, 0)
- //endTimes := endTime.Format("2006-01-02")
- //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
-
- org_id := c.GetMobileAdminUserInfo().Org.Id
-
- //if org_id == 10579 {
- // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "list": list,
- // })
- // return
- //} else {
- // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "list": list,
- // })
- // return
- //}
- if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
- list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- } else {
- list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- return
-
- }
-
- func (c *DialysisAPIController) BathDeleteAdviceList() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- ids := c.GetString("ids")
-
- idArray := strings.Split(ids, ",")
- origin, _ := c.GetInt64("origin")
- if origin == 1 {
- err = service.BatchDeleteAdvice(idArray)
- fmt.Print("err", err)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "批量删除成功",
- })
- return
- }
-
- if origin == 2 {
- service.BatchDeleteHisAdvice(idArray)
- }
- }
-
- func (c *DialysisAPIController) UpdateAutoReduceDetail() {
-
- good_id, _ := c.GetInt64("good_id")
- count, _ := c.GetInt64("count")
- record_time, _ := c.GetInt64("record_time")
- patient_id, _ := c.GetInt64("patient_id")
- detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "detail": detail,
- })
- return
- }
-
- func (c *DialysisAPIController) DeleteAutoReduceDetail() {
-
- good_id, _ := c.GetInt64("good_id")
- record_time, _ := c.GetInt64("record_time")
- patient_id, _ := c.GetInt64("patient_id")
- service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
-
- err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
- fmt.Print("err", err)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "批量删除成功",
- })
- return
- }
-
- func (c *DialysisAPIController) BatchAdviceCheck() {
-
- ids := c.GetString("ids")
- idArray := strings.Split(ids, ",")
- creator, _ := c.GetInt64("creator")
- origin, _ := c.GetInt64("origin")
- if origin == 1 {
- err := service.BatchAdviceCheck(idArray, creator)
- fmt.Println(err)
- list, _ := service.GetAdviceExecutionById(idArray)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
- if origin == 2 {
- service.BatchHisAdviceCheck(idArray, creator)
- list, _ := service.GetHisAdviceExecutionById(idArray)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
-
- }
-
- func (c *DialysisAPIController) BatchAdviceExecution() {
-
- ids := c.GetString("ids")
-
- idArray := strings.Split(ids, ",")
- executionTime := c.GetString("execution_time")
-
- creator, _ := c.GetInt64("creator")
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
-
- orgin, _ := c.GetInt64("origin")
- if orgin == 1 {
- err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
- list, _ := service.GetAdviceExecutionById(idArray)
- fmt.Println(err)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
-
- if orgin == 2 {
- err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
- list, _ := service.GetHisAdviceExecutionById(idArray)
- fmt.Println(err)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
-
- }
-
- func (c *DialysisAPIController) UpdateStockGoods() {
-
- good_id, _ := c.GetInt64("good_id")
- record_time, _ := c.GetInt64("record_time")
- patient_id, _ := c.GetInt64("patient_id")
- count, _ := c.GetInt64("count")
-
- err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
-
- fmt.Print("err", err)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "更新成功",
- })
- return
- }
-
- // 当前数据比上一次出库数据少
- func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
-
- //查询该患者当天已经出库的耗材信息
- goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
- // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
- for i := len(goods_yc) - 1; i >= 0; i-- {
- goods_yc_temp := goods_yc[i]
- for j := len(goods) - 1; j >= 0; j-- {
- goods_temp := goods[j]
- // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
- if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
- // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
- if goods_yc_temp.Count == goods_temp.Count {
- goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
- goods = append(goods[:j], goods[j+1:]...)
- break
- }
- // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
- if goods_yc_temp.Count > goods_temp.Count {
-
- temp_count := goods_yc_temp.Count - goods_temp.Count
- goods_yc[i].Count = temp_count
- goods = append(goods[:j], goods[j+1:]...)
- break
- }
- // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
- if goods_yc_temp.Count < goods_temp.Count {
- temp_count := goods_temp.Count - goods_yc_temp.Count
-
- goods[j].Count = temp_count
- goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
-
- break
- }
- }
- }
- }
-
- // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
- // goods 这个数据就是需要出库的耗材的数据(新增的数据)
-
- //退库
- if len(goods_yc) > 0 {
- for _, good_yc := range goods_yc {
- out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
- ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
- }
- }
-
- return nil
- }
-
- // 耗材出库删除
- func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
-
- // 先根据相关信息查询当天该耗材的出库信息
- warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
-
- if err != nil {
- return err
- }
-
- var delete_count int64 = 0
-
- delete_count = warehouseOutInfos.Count - count
-
- houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
-
- // 在出库记录表里记录退库详情
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- OrgId: orgID,
- Type: 1,
- IsSys: 1,
- SysRecordTime: record_time,
- GoodTypeId: good_yc.GoodTypeId,
- GoodId: good_yc.GoodId,
- PatientId: good_yc.PatientId,
- ConsumableType: 2,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- warehouseOutInfo.Count = count
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.Dealer = stockInInfo.Dealer
- warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
- warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
- warehouseOutInfo.ProductDate = stockInInfo.ProductDate
- warehouseOutInfo.Number = warehouseOutInfos.Number
- warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
- warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
- //查找当天是否存在出库记录
-
- _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
-
- if errcod == gorm.ErrRecordNotFound {
- errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- //插入详情明细表
- stockFlow := models.VmStockFlow{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_yc.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- UserOrgId: good_yc.OrgId,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
- if errflow == gorm.ErrRecordNotFound {
- //创建流水表
- err := service.CreateStockFlowOne(stockFlow)
- fmt.Println("err", err)
- } else if errflow == nil {
- //插入详情明细表
- stockFlow := models.VmStockFlow{
- ID: exsit.ID,
- WarehousingId: warehouseOutInfos.WarehouseInfotId,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_yc.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: exsit.Count - delete_count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- UserOrgId: good_yc.OrgId,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
- }
-
- if errOne != nil {
- return errOne
- }
- } else if errcod == nil {
- service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
- //插入详情明细表
- stockFlow := models.VmStockFlow{
- WarehousingId: warehouseOutInfos.WarehouseInfotId,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_yc.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- UserOrgId: good_yc.OrgId,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- ReturnCount: delete_count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
- if errflows == gorm.ErrRecordNotFound {
- //创建流水表
- service.CreateStockFlowOne(stockFlow)
- } else if errflows == nil {
- stockFlow := models.VmStockFlow{
- WarehousingId: warehouseOutInfos.WarehouseInfotId,
- ID: exsit.ID,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_yc.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: exsit.Count - delete_count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- UserOrgId: good_yc.OrgId,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- ReturnCount: delete_count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
- }
-
- }
-
- //更改自动出库的表格
- details := models.BloodAutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient_id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: record_time,
- OrgId: orgID,
- GoodId: good_yc.GoodId,
- GoodTypeId: good_yc.GoodTypeId,
- Count: count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //查询当天耗材是否已经存在数据
- _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
-
- if errcode == gorm.ErrRecordNotFound {
- errTwo := service.CreateAutoReduceRecord(&details)
- if errTwo != nil {
- return errTwo
- }
- } else if errcode == nil {
- service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
- service.CreateAutoReduceRecord(&details)
-
- }
-
- service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
-
- //增加出库库存数量
- service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
-
- errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
- fmt.Println("errOne", errOne)
- // 删除出库完成后,要增加对应批次的库存数量
-
- errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
- if errThree != nil {
- return errThree
- }
-
- if good_yc.Count == 0 {
- return nil
- } else {
- return errors.New("退库和出库数据不匹配")
- }
- }
-
- func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
-
- //查询该患者当天已经出库的耗材信息
- goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
- // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
- for i := len(goods_yc) - 1; i >= 0; i-- {
- goods_yc_temp := goods_yc[i]
- for j := len(goods) - 1; j >= 0; j-- {
- goods_temp := goods[j]
- // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
- if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
- // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
- if goods_yc_temp.Count == goods_temp.Count {
- goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
- goods = append(goods[:j], goods[j+1:]...)
- break
- }
- // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
- if goods_yc_temp.Count > goods_temp.Count {
-
- temp_count := goods_yc_temp.Count - goods_temp.Count
- goods_yc[i].Count = temp_count
- goods = append(goods[:j], goods[j+1:]...)
- break
- }
- // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
- if goods_yc_temp.Count < goods_temp.Count {
- temp_count := goods_temp.Count - goods_yc_temp.Count
- goods[j].Count = temp_count
- goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
- break
- }
- }
- }
- }
-
- // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
- // goods 这个数据就是需要出库的耗材的数据(新增的数据)
-
- fmt.Println("剩余需要出库的", len(goods))
- if len(goods) > 0 {
- out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
- houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
- if err == gorm.ErrRecordNotFound {
- //没有记录,则创建出库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(orgID)
- total = total + 1
- warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: time.Now().Unix(),
- OrgId: orgID,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: record_time,
- Dealer: 0,
- Manufacturer: 0,
- Type: 1,
- IsSys: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- err := service.AddSigleWarehouseOut(&warehouseOut)
- if err != nil {
- utils.TraceLog("创建出库单失败 err = %v", err)
- return err
- } else {
- out = warehouseOut
- }
- }
-
- for _, item := range goods {
- var newCount int64 = 0
- for _, it := range goodOne {
- if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
- newCount = it.Count
- }
- }
- prepare := models.DialysisBeforePrepare{
- GoodTypeId: item.GoodTypeId,
- GoodId: item.GoodId,
- Count: item.Count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
-
- //增加出库数量
- service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
- }
-
- }
-
- if len(goods_yc) > 0 {
-
- for _, good_yc := range goods_yc {
- out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
- ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
- }
- }
-
- return nil
- }
-
- // 耗材出库删除
- func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
- // 先根据相关信息查询当天该耗材的出库信息
- warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
- if err != nil {
- return err
- }
-
- var delete_count int64 = 0
-
- for _, ware := range warehouseOutInfos {
- // 判断当前出库的数据和删除出库数量
- if good_yc.Count <= ware.Count {
- delete_count = good_yc.Count
- } else {
- delete_count = ware.Count
- }
-
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: orgID,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 0,
- SysRecordTime: record_time,
- GoodTypeId: good_yc.GoodTypeId,
- GoodId: good_yc.GoodId,
- StorehouseId: warehouseOut.StorehouseId,
- IsCheck: 1,
- }
- warehouseOutInfo.Count = delete_count
- stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
- warehouseOutInfo.Price = stockInInfo.Price
- errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- if errOne != nil {
- return errOne
- }
-
- // 删除出库完成后,要改变流水库存(有疑问)
- errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
-
- fmt.Println("errOne", errOne)
- errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
-
- service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
-
- //扣减出库数量
- service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
- if errThree != nil {
- return errThree
- }
- }
-
- if good_yc.Count == 0 {
- return nil
- } else {
- return errors.New("退库和出库数据不匹配")
- }
- }
-
- func (this *DialysisAPIController) GetMobileScheduleList() {
-
- limit, _ := this.GetInt64("limit")
-
- page, _ := this.GetInt64("page")
-
- type_options_visible, _ := this.GetInt64("type_options_visible")
- sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
- zone_options_visible, _ := this.GetInt64("zone_options_visible")
- fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
- }
-
- func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
- newArr = make([]*models.HisPrescriptionProject, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func (this *DialysisAPIController) GetRoleList() {
-
- admin_user_id, _ := this.GetInt64("admin_user_id")
- orgid := this.GetMobileAdminUserInfo().Org.Id
- list, err := service.GetRoleList(orgid, admin_user_id)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
-
- func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
-
- // 先根据相关信息查询当天该耗材的出库信息
- warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
-
- if err != nil {
- return err
- }
-
- var delete_count int64 = 0
-
- delete_count = warehouseOutInfos.Count - count
-
- houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
-
- // 删除出库完成后,要增加对应批次的库存数量
-
- errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
- if errThree != nil {
- return errThree
- }
-
- //增加退库数量
- service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
-
- //扣减出库数量
- service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
- //查询剩余库存
- goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
- var sum_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- }
-
- // 在出库记录表里记录退库详情
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- OrgId: orgID,
- Type: 1,
- IsSys: 1,
- SysRecordTime: record_time,
- GoodTypeId: good_yc.GoodTypeId,
- GoodId: good_yc.GoodId,
- PatientId: good_yc.PatientId,
- ConsumableType: 2,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- OverCount: sum_count,
- }
- warehouseOutInfo.Count = count
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.Dealer = stockInInfo.Dealer
- warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
- warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
- warehouseOutInfo.ProductDate = stockInInfo.ProductDate
- warehouseOutInfo.Number = warehouseOutInfos.Number
- warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
- warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
- //查找当天是否存在出库记录
-
- _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
-
- if errcod == gorm.ErrRecordNotFound {
- errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- //插入详情明细表
- if errOne != nil {
- return errOne
- }
- //插入详情明细表
- stockFlow := models.VmStockFlow{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_yc.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: record_time,
- UserOrgId: good_yc.OrgId,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: sum_count,
- ProjectId: good_yc.ProjectId,
- }
- err := service.CreateStockFlowOne(stockFlow)
- fmt.Println("err", err)
- } else if errcod == nil {
- service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
- }
-
- //创建退库单
- operation_time := time.Now().Unix()
-
- //创建退库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllCancelStockTotal(orgID)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: orgID,
- Creater: warehouseOut.Creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- ReturnTime: record_time,
- Type: 1,
- StorehouseId: stockInInfo.StorehouseId,
- IsCheck: 1,
- }
- _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
- if msgerrkonde == gorm.ErrRecordNotFound {
- service.AddSigleCancelStock(&cancelStock)
- }
-
- cancel, _ := service.GetLastCancelStockById(orgID)
-
- manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
- deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
- cancelStockInfo := models.CancelStockInfo{
- GoodId: stockInInfo.GoodId,
- CancelStockId: cancel.ID,
- GoodTypeId: stockInInfo.GoodTypeId,
- Count: delete_count,
- Price: stockInInfo.PackingPrice,
- Total: 0,
- ProductDate: stockInInfo.ProductDate,
- ExpiryDate: stockInInfo.ExpiryDate,
- Ctime: record_time,
- Status: 1,
- OrgId: orgID,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: stockInInfo.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: stockInInfo.ID,
- PatientId: patient_id,
- RecordDate: record_time,
- StorehouseId: stockInInfo.StorehouseId,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
-
- cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
-
- flow := models.VmStockFlow{
- WarehousingId: warehouseOutInfo.WarehouseInfotId,
- GoodId: good_yc.GoodId,
- Number: warehouseOutInfos.Number,
- LicenseNumber: stockInInfo.LicenseNumber,
- Count: delete_count,
- UserOrgId: orgID,
- PatientId: patient_id,
- SystemTime: record_time,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: warehouseOutInfos.WarehouseOutId,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: warehouseOut.Creater,
- UpdateCreator: 0,
- Status: 1,
- Ctime: record_time,
- Mtime: 0,
- Price: stockInInfo.Price,
- WarehousingDetailId: stockInInfo.ID,
- WarehouseOutDetailId: warehouseOutInfos.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: sum_count,
- }
- service.CreateStockFlowOne(flow)
-
- //更改自动出库的表格
- details := models.BloodAutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient_id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: record_time,
- OrgId: orgID,
- GoodId: good_yc.GoodId,
- GoodTypeId: good_yc.GoodTypeId,
- Count: count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //查询当天耗材是否已经存在数据
- _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
-
- if errcode == gorm.ErrRecordNotFound {
- errTwo := service.CreateAutoReduceRecord(&details)
- if errTwo != nil {
- return errTwo
- }
- } else if errcode == nil {
- service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
- service.CreateAutoReduceRecord(&details)
-
- }
-
- service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
-
- //增加出库库存数量
- //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
-
- if good_yc.Count == 0 {
- return nil
- } else {
- return errors.New("退库和出库数据不匹配")
- }
- }
-
- func (this *DialysisAPIController) SavePatientSign() {
-
- adminUserInfo := this.GetMobileAdminUserInfo()
- patient_id, _ := this.GetInt64("patient_id")
- dialysis_date, _ := this.GetInt64("dialysis_date")
- orgid := adminUserInfo.Org.Id
-
- var esdata models.DialysisOrder
- var err error
- if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- esdata.Hash = esdata.Hash
- esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
-
- order := models.DialysisOrder{
- Hash: esdata.Hash,
- Url: esdata.Url,
- }
- err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
- redis := service.RedisClient()
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
-
- //清空key 值
- redis.Set(keyOne, "", time.Second)
- //scheduleDateStartOne := startDate.Format("2006-01-02")
- //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- //redis.Set(keyTwo, "", time.Second)
-
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
- redis.Set(keyThree, "", time.Second)
- keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
- redis.Set(keyFour, "", time.Second)
-
- keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
- redis.Set(keyFive, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
- redis.Set(keySeven, "", time.Second)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "electronic_signature": esdata,
- })
- }
-
- func (this *DialysisAPIController) GetPatientSign() {
-
- patient_id, _ := this.GetInt64("patient_id")
-
- dialysis_date, _ := this.GetInt64("dialysis_date")
- adminUserInfo := this.GetMobileAdminUserInfo()
- orgId := adminUserInfo.Org.Id
- dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "dialysisOrder": dialysisOrder,
- })
- }
-
- func (this *DialysisAPIController) GetScheduleByPatient() {
-
- patient_id, _ := this.GetInt64("patient_id")
- schedule_date, _ := this.GetInt64("schedule_date")
- orgid := this.GetMobileAdminUserInfo().Org.Id
- schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
- this.ServeSuccessJSON(map[string]interface{}{
- "schedule": schedule,
- })
-
- }
-
- func (this *DialysisAPIController) GetDialysisRecordOrder() {
-
- org_id := this.GetMobileAdminUserInfo().Org.Id
- patient_id, _ := this.GetInt64("patient_id")
- schedule_date, _ := this.GetInt64("schedule_date")
- order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
- this.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- })
- }
-
- func (this *DialysisAPIController) GetScheduleTypeByIdList() {
-
- org_id := this.GetMobileAdminUserInfo().Org.Id
-
- schedule_date := this.GetString("schedule_date")
- schedule_type, _ := this.GetInt64("schedule_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startdateunix int64
-
- if len(schedule_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startdateunix = theTime.Unix()
- }
-
- list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
- scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
- devices, _ := service.GetAllDevicetByListSix(org_id)
- for key, item := range scheduals {
- // 床位信息
- for _, device := range devices {
- if item.BedId == device.ID {
- scheduals[key].DeviceNumber = device
- break
- }
- }
-
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "scheduals": scheduals,
- })
- }
-
- func (this *DialysisAPIController) SavePatientPicture() {
-
- patient_id, _ := this.GetInt64("patient_id")
- dialysis_date, _ := this.GetInt64("schedule_date")
- avatar := this.GetString("avatar")
- fmt.Println("patient_id", patient_id)
- orgId := this.GetMobileAdminUserInfo().Org.Id
-
- order := models.DialysisOrder{
- Url: avatar,
- }
- err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
- redis := service.RedisClient()
-
- key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
- //清空key 值
- redis.Set(keyOne, "", time.Second)
- keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
- redis.Set(keyThree, "", time.Second)
- keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
- redis.Set(keyFour, "", time.Second)
-
- keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
- redis.Set(keyFive, "", time.Second)
-
- keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
- redis.Set(keySeven, "", time.Second)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- })
- }
-
- func (this *DialysisAPIController) ExectionMobileAdvice() {
-
- ids := this.GetString("ids")
- idSplit := strings.Split(ids, ",")
- orgId := this.GetMobileAdminUserInfo().Org.Id
-
- config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
- execution_time := this.GetString("exce_time")
- timeLayout2 := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //his客户
- if config.IsOpen == 1 {
-
- list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
- adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
- for _, item := range list {
- for _, it := range adviceList {
- if item.DrugId == it.DrugId {
- item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
- }
- }
- }
-
- for _, item := range list {
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- var sum_out_count int64
- for _, itemThree := range item.ChildDoctorAdvice {
- var prescribing_number int64
- stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
- parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
- if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber * medical.MinNumber
- }
- if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber
- }
- if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber
- }
- sum_out_count += prescribing_number
- }
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
-
- //库存不足
- if sum_out_count > drugStockOut.FlushCount {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "drug": medical,
- "ids": ids,
- })
- return
- }
- }
- creater := this.GetMobileAdminUserInfo().AdminUser.Id
- //执行医嘱
- errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
- advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
- for _, item := range advices {
- key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- }
- if errs == nil {
-
- //药品管理信息
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- if drugStockConfig.IsOpen == 1 {
- for _, item := range advices {
- advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
- config, _ := service.GetDrugOpenConfigOne(orgId)
- if config.IsOpen != 1 {
- //查询该药品是否有库存
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
- if medical.IsUse == 2 {
- if config.IsOpen != 1 {
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- service.HisDrugsDelivery(orgId, creater, &advice)
- if orgId == 3877 || orgId == 10265 {
- //查询该药品是否有出库记录
- flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
- if len(flowMap) == 0 {
- errs := service.UpdateHisAdviceById(advice.ID)
- if errs != nil {
- drugError := models.XtDrugError{
- UserOrgId: orgId,
- DrugId: item.DrugId,
- RecordDate: item.AdviceDate,
- PatientId: item.PatientId,
- Remark: "透析医嘱页面出库记录为空,更新执行人失败",
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- SumCount: 0,
- Prescribingnumber: advice.PrescribingNumber,
- PrescribingNumberUnit: advice.PrescribingNumberUnit,
- }
- service.CreateDrugError(drugError)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "drug": medical,
- "ids": ids,
- })
- return
-
- }
- }
- }
- if pharmacyConfig.IsOpen != 1 {
- service.HisDrugsDelivery(orgId, creater, &advice)
- if orgId == 3877 || orgId == 10265 {
- //查询该药品是否有出库记录
- flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
- if len(flowMap) == 0 {
- errs := service.UpdateHisAdviceById(advice.ID)
- if errs != nil {
- drugError := models.XtDrugError{
- UserOrgId: orgId,
- DrugId: item.DrugId,
- RecordDate: item.AdviceDate,
- PatientId: item.PatientId,
- Remark: "透析医嘱页面出库记录为空,更新执行人失败",
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- SumCount: 0,
- Prescribingnumber: advice.PrescribingNumber,
- PrescribingNumberUnit: advice.PrescribingNumberUnit,
- }
- service.CreateDrugError(drugError)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "drug": medical,
- "ids": ids,
- })
- return
- }
- }
- }
-
- //更新字典里面的库存
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- }
-
- }
-
- }
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "ids": ids,
- })
- return
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
- //血透客户
- if config.IsOpen == 2 || config.IsOpen == 0 {
-
- //药品管理信息
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
- if drugStockConfig.IsOpen == 1 {
- list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
- adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
- for _, item := range list {
- for _, it := range adviceList {
- if item.DrugId == it.DrugId {
- item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
- }
- }
- }
- for _, item := range list {
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- var sum_out_count int64
- for _, itemThree := range item.ChildDoctorAdvice {
- var prescribing_number int64
- stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
- parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
- if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber * medical.MinNumber
- }
- if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber
- }
- if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber
- }
- sum_out_count += prescribing_number
- }
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
-
- //库存不足
- if sum_out_count > drugStockOut.FlushCount {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "drug": medical,
- "ids": ids,
- })
- return
- }
- }
-
- creater := this.GetMobileAdminUserInfo().AdminUser.Id
-
- //执行医嘱
- errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
- advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
- for _, item := range advices {
- key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- }
- if errs == nil {
-
- for _, item := range advices {
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- //查询是否出库按钮开启
- adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
- if adviceSetting.IsAdviceOpen == 1 {
- //查询是否出库按钮开启
- prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
- pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
- if prescriptionConfig.IsOpen == 1 {
- if medical.IsUse == 2 {
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
- }
- if pharmacyConfig.IsOpen != 1 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
- }
-
- //更新字典里面的库存
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- }
- }
- } else {
- pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
- if medical.IsUse == 2 {
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
- }
- if pharmacyConfig.IsOpen != 1 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
- }
-
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- }
- }
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "ids": ids,
- })
- return
-
- } else {
-
- creater := this.GetMobileAdminUserInfo().AdminUser.Id
- //执行医嘱
- service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
- advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
- for _, item := range advices {
- key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "ids": ids,
- })
- return
- }
-
- }
-
- }
-
- func (this *DialysisAPIController) GetSettleMobileAdvice() {
-
- ids := this.GetString("ids")
- idSplit := strings.Split(ids, ",")
- orgId := this.GetMobileAdminUserInfo().Org.Id
- config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
-
- if config.IsOpen == 1 {
- service.UpdateSettleMobileHisAdvice(orgId, idSplit)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "ids": ids,
- })
- return
- }
-
- if config.IsOpen == 0 || config.IsOpen == 2 {
-
- service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "ids": ids,
- })
- return
- }
- }
-
- func (this *DialysisAPIController) GetCheckMobileAdvice() {
-
- ids := this.GetString("ids")
- idSplit := strings.Split(ids, ",")
- orgId := this.GetMobileAdminUserInfo().Org.Id
-
- config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
-
- //his
- if config.IsOpen == 1 {
- checker := this.GetMobileAdminUserInfo().AdminUser.Id
- theTime := time.Now()
-
- advices := models.HisDoctorAdviceThirty{
- CheckTime: theTime.Unix(),
- Checker: checker,
- UpdatedTime: time.Now().Unix(),
- }
- service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
-
- list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
- for _, item := range list {
- key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- defer redis.Close()
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "ids": ids,
- })
- return
- }
-
- //血透
- if config.IsOpen == 0 || config.IsOpen == 2 {
-
- checker := this.GetMobileAdminUserInfo().AdminUser.Id
- theTime := time.Now()
-
- advices := models.DoctorAdvice{
- CheckTime: theTime.Unix(),
- Checker: checker,
- UpdatedTime: time.Now().Unix(),
- }
-
- service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
- list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
- for _, item := range list {
- key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- defer redis.Close()
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "ids": ids,
- })
- return
- }
-
- }
-
- func (this *DialysisAPIController) CheckSchedule() {
-
- patientID, _ := this.GetInt64("patient_id")
- recordDateStr := this.GetString("record_date")
- nurseID, _ := this.GetInt64("start_nurse")
- schedual_type, _ := this.GetInt64("schedual_type")
-
- bedID, _ := this.GetInt64("bed")
- start_time := this.GetString("start_time")
-
- fmt.Println("patientID", patientID)
- fmt.Println("recordDateStr", recordDateStr)
- fmt.Println("nurseID", nurseID)
- fmt.Println("schedual_type------", schedual_type)
- if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
- if parseStartDateErr != nil {
- this.ErrorLog("时间解析失败:%v", parseStartDateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseErr != nil {
- this.ErrorLog("时间解析失败:%v", parseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetMobileAdminUserInfo()
- patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
- if getPatientErr != nil {
- this.ErrorLog("获取患者信息失败:%v", getPatientErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if patient == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
- if getNurseErr != nil {
- this.ErrorLog("获取护士失败:%v", getNurseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- this.ErrorLog("护士不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
- if getDeviceNumberErr != nil {
- this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if deviceNumber == nil {
- this.ErrorLog("床位号不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
- if getRecordErr != nil {
- this.ErrorLog("获取透析记录失败:%v", getRecordErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if dialysisRecord != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
- return
- }
-
- scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
- scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
- schedulestartTime := theStartTime.Unix()
- scheduleendTime := theEndTime.Unix()
-
- //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
- //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
-
- schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
-
- //查询该床位是否有人用了
- order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
-
- if err == nil {
- if schedule.ID == 0 {
- this.ServeSuccessJSON(map[string]interface{}{
- "status": 0,
- "msg": "请求失败",
- })
-
- } else {
-
- if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
- if order.ID > 0 { //该机位被其他人占用了
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
- return
- } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
- if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
-
- this.ServeSuccessJSON(map[string]interface{}{
- "status": 1,
- "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
- })
- return
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "status": 0,
- "msg": "",
- })
- }
- }
- } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
- this.ServeSuccessJSON(map[string]interface{}{
- "status": 2,
- "msg": "当前机位已有患者在使用,请重新选择!",
- })
-
- }
-
- }
-
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "status": 0,
- "msg": "",
- })
-
- }
-
- }
-
- func (this *DialysisAPIController) GetNewDoctorListToday() {
-
- orgId := this.GetMobileAdminUserInfo().Org.Id
-
- schedule_type, _ := this.GetInt64("schedule_type")
-
- partion_type, _ := this.GetInt64("partion_type")
-
- start_time := this.GetString("start_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
- _, config := service.FindXTHisRecordByOrgId(orgId)
- appId := this.GetMobileAdminUserInfo().App.Id
- doctorList, _ := service.GetAllAdminUsers(orgId, appId)
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "config": config,
- "doctorList": doctorList,
- })
- return
-
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (this *DialysisAPIController) SaveMobileInformation() {
-
- patient_id, _ := this.GetInt64("patient_id")
- record_date, _ := this.GetInt64("record_date")
- startTime := this.GetString("start_time")
- module, _ := this.GetInt64("module")
- remark := this.GetString("remark")
- timeLayout := "2006-01-02 15:04"
- loc, _ := time.LoadLocation("Local")
-
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- StartTime := theTime.Unix()
- fmt.Println("startime-------------", StartTime)
- creater := this.GetMobileAdminUserInfo().AdminUser.Id
-
- user_org_id := this.GetMobileAdminUserInfo().Org.Id
-
- information := models.XtDialysisInformation{
- Module: module,
- PatientId: patient_id,
- RecordDate: record_date,
- ApplicationDate: StartTime,
- Creater: creater,
- ApplicationStatus: 2,
- Checker: 0,
- CheckTime: 0,
- Remark: remark,
- UserOrgId: user_org_id,
- Ctime: time.Now().Unix(),
- Status: 1,
- Mtime: 0,
- }
-
- infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
- if infor.ID == 0 {
- service.SaveDialysisInformation(information)
- }
- if infor.ID > 0 {
- service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "information": information,
- })
- return
- }
-
- func (this *DialysisAPIController) GetMobileInformation() {
-
- limit, _ := this.GetInt64("limit")
-
- page, _ := this.GetInt64("page")
-
- orgid := this.GetMobileAdminUserInfo().Org.Id
- information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
- appid := this.GetMobileAdminUserInfo().App.Id
- doclist, _ := service.GetAllDoctorSix(orgid, appid)
- patients, _ := service.GetAllpatientThirty(orgid)
- this.ServeSuccessJSON(map[string]interface{}{
- "information": information,
- "total": total,
- "doclist": doclist,
- "patients": patients,
- })
- return
-
- }
-
- func (this *DialysisAPIController) GetMobileInformationOne() {
-
- limit, _ := this.GetInt64("limit")
-
- page, _ := this.GetInt64("page")
-
- orgid := this.GetMobileAdminUserInfo().Org.Id
- information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
- appid := this.GetMobileAdminUserInfo().App.Id
- doclist, _ := service.GetAllDoctorSix(orgid, appid)
- patients, _ := service.GetAllpatientThirty(orgid)
- this.ServeSuccessJSON(map[string]interface{}{
- "information": information,
- "total": total,
- "doclist": doclist,
- "patients": patients,
- })
- return
- }
-
- func (this *DialysisAPIController) CheckMobileInformation() {
-
- id, _ := this.GetInt64("id")
-
- application_status, _ := this.GetInt64("application_status")
-
- checker := this.GetMobileAdminUserInfo().AdminUser.Id
- checktime := time.Now().Unix()
- err := service.CheckMobileInformation(id, application_status, checker, checktime)
-
- if err == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- }
-
- func (c *DialysisAPIController) GetControlMonitorList() {
-
- partition, _ := c.GetInt64("partition")
- monitorDate := c.GetString("date")
- patient_id, _ := c.GetInt64("patient_id")
- pat_type, _ := c.GetInt64("pat_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTime int64
- if len(monitorDate) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
- if err != nil {
- theStartTime = 0
- }
- theStartTime = theTime.Unix()
- }
- adminInfo := c.GetMobileAdminUserInfo()
- orgID := adminInfo.Org.Id
- monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
-
- if err != nil {
- c.ErrorLog("获取排班信息失败:%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- } else {
- if len(monitor) > 0 {
- //获取所有床位
- numberList, _ := service.GetAllDeviceNumberByList(orgID)
- //获取所有分区
- zoneList, _ := service.GetAllZoneByList(orgID)
- //获取透析处方
- prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
- //获取透前评估
- assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
- //获取上机
- dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
- //获取透后
- AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
-
- //获取透后监测
- monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
-
- //获取所有的患者
- patients, _ := service.GetAllPatientListByListOne(orgID)
-
- //获取所有透析模式
- treatments, _ := service.GetAllTreatModeByList(orgID)
-
- //获取所有医嘱
- adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
-
- //获取双人核对
- checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
-
- //治疗小结
- summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
-
- //待消毒
- informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
-
- for key, item := range monitor {
- // 获取床位信息
- for _, it := range numberList {
- if item.BedId == it.ID {
- monitor[key].DeviceNumber = it
- break
- }
- }
-
- //获取分区信息
- for _, it := range zoneList {
- if item.PartitionId == it.ID {
- monitor[key].DeviceZone = it
- }
- }
-
- for _, prescription := range prescriptions {
- if item.PatientId == prescription.PatientId {
- monitor[key].Prescription = prescription
- break
- }
- }
-
- for _, it := range checkList {
- if item.PatientId == it.PatientId {
- monitor[key].DoubleCheck = it
- break
- }
- }
-
- for _, it := range summaryList {
- if item.PatientId == it.PatientId {
- monitor[key].TreatmentSummaryForList = it
- break
- }
- }
-
- // 透前评估
- for _, assessmentBefore := range assessmentBefores {
- if item.PatientId == assessmentBefore.PatientId {
- monitor[key].AssessmentBeforeDislysis = assessmentBefore
- break
- }
- }
-
- // 透析上下机
- for _, dialysisOrder := range dialysisOrders {
- if item.PatientId == dialysisOrder.PatientId {
- monitor[key].DialysisOrder = dialysisOrder
- break
- }
- }
-
- // 治疗小节
- for _, afterDislysis := range AssessmentAfterDislysis {
- if item.PatientId == afterDislysis.PatientId {
- monitor[key].AssessmentAfterDislysis = afterDislysis
- break
- }
- }
-
- for _, it := range monitorlist {
- if item.PatientId == it.PatientId {
- monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
- }
- }
-
- for _, it := range adviceList {
- if item.PatientId == it.PatientId {
- monitor[key].AdviceList = append(monitor[key].AdviceList, it)
- }
- }
-
- for _, patient := range patients {
- if item.PatientId == patient.ID {
- monitor[key].MonitorPatients = patient
- break
- }
- }
-
- for _, treatment := range treatments {
- if item.ModeId == treatment.ID {
- monitor[key].TreatmentMode = treatment
- break
- }
- }
-
- for _, infor := range informationList {
- if item.PatientId == infor.PatientId {
- monitor[key].NewDeviceInformation = infor
- break
- }
- }
- }
- }
-
- }
-
- patients, err := service.GetAllpatientFourty(orgID)
-
- var mds []*models.NewMonitorDialysisScheduleList
-
- if pat_type == 0 {
- for _, item := range monitor {
- mds = append(mds, item)
- }
- }
-
- //待医嘱核对
- if pat_type == 1 {
- for _, item := range monitor {
- if len(item.AdviceList) > 0 {
- mds = append(mds, item)
- }
- }
- }
- //待开小结
- if pat_type == 2 {
- for _, item := range monitor {
- if item.TreatmentSummaryForList == nil {
-
- mds = append(mds, item)
-
- }
-
- }
- }
- //待下机
- if pat_type == 3 {
- for _, item := range monitor {
- if item.DialysisOrder != nil {
- if item.DialysisOrder.ID > 0 {
- mds = append(mds, item)
- }
- }
-
- }
- }
-
- //待消毒
- if pat_type == 4 {
- for _, item := range monitor {
- if item.NewDeviceInformation == nil {
- mds = append(mds, item)
- }
-
- }
- }
- //待双人核对
- if pat_type == 5 {
- for _, item := range monitor {
- if item.DoubleCheck == nil {
-
- mds = append(mds, item)
-
- }
-
- }
- }
-
- //医嘱未执行
- if pat_type == 6 {
- for _, item := range monitor {
- if len(item.AdviceList) > 0 {
- mds = append(mds, item)
- }
- }
- }
- //患者未签名
- if pat_type == 7 {
- for _, item := range monitor {
- if item.DialysisOrder != nil {
- if item.DialysisOrder.ID > 0 {
- mds = append(mds, item)
- }
- }
-
- }
- }
- //目标超滤于实际超滤不同
- if pat_type == 8 {
- for _, item := range monitor {
- if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
- if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
- mds = append(mds, item)
- }
- }
-
- }
- }
- //血压少于5次
- if pat_type == 9 {
- for _, item := range monitor {
- if len(item.MonitoringRecord) < 5 {
- mds = append(mds, item)
- }
- }
- }
-
- if pat_type == 10 {
- for _, item := range monitor {
- if len(item.MonitoringRecord) == 0 {
- mds = append(mds, item)
- }
- }
- }
-
- if pat_type == 11 {
- for _, item := range monitor {
- if len(item.MonitoringRecord) > 0 {
- mds = append(mds, item)
- }
- }
- }
- if pat_type == 12 {
- for _, item := range monitor {
- if len(item.MonitoringRecord) > 0 {
- mds = append(mds, item)
- }
- }
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "monitor": mds,
- "patients": patients,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- func (c *DialysisAPIController) GetAdviceListNoExecution() {
-
- admin_user_id, _ := c.GetInt64("admin_user_id")
- timeStr := time.Now().Format("2006-01-02")
- timeLayout := "2006-01-02 15:04:05"
- timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
- timenow := timeStringToTime.Unix()
-
- orgId := c.GetMobileAdminUserInfo().Org.Id
-
- //查询当前护士的患者
- orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
- var patientIds []int64
-
- for _, item := range orderList {
- patientIds = append(patientIds, item.PatientId)
- }
-
- adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
-
- hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
-
- projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
-
- //药品管理信息
- _, drugStockConfig := service.FindHisConfig(orgId)
-
- _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
-
- patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "adviceList": adviceList,
- "hisAdviceList": hisAdviceList,
- "projectList": projectList,
- "drugStockConfig": drugStockConfig,
- "patientList": patientList,
- "projectConfig": projectConfig,
- })
-
- }
-
- func (c *DialysisAPIController) GetLastAcceptRecrods() {
-
- patient_id, _ := c.GetInt64("patient_id")
- recrods, _ := service.GetLastAcceptRecrods(patient_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "recrods": recrods,
- })
- }
-
- func (c *DialysisAPIController) ExMobileChangeSch() {
-
- id_one, _ := c.GetInt64("id_one")
- id_two, _ := c.GetInt64("id_two")
- sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
- sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
-
- //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
- //if order2.ID > 0 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
- // return
- //}
-
- //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
- if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
- count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
- if count > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
- return
- }
-
- count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
- if count1 > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
- return
- }
- }
-
- err := service.UpdateScheduleThree(sch, sch_two)
-
- order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
- if order.ID > 0 {
- scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
- service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
- redis := service.RedisClient()
- key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
-
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- }
-
- orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
- if orderOne.ID > 0 {
- scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
- service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
- redis := service.RedisClient()
- key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- }
-
- if err == nil {
-
- //去除当天患者排班中重复数据,保留最后一条数据
- service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
- service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "交换成功",
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
- }
-
- func (c *DialysisAPIController) MobileCoverSch() {
-
- id_one, _ := c.GetInt64("id_one")
- id_two, _ := c.GetInt64("id_two")
- sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
- //针对凤凰医院
- if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
- advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
- if len(advice) > 0 {
- service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
- }
- }
-
- if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
- hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
- project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
- if len(hisAdvice) > 0 {
- service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
- }
- if len(project) > 0 {
- service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
- }
- }
- sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
-
- //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
- if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
- count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
- if count > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
- return
- }
- }
-
- var new_sch models.Schedule
- new_sch = sch
- new_sch.BedId = sch_two.BedId
- new_sch.ScheduleDate = sch_two.ScheduleDate
- new_sch.ScheduleWeek = sch_two.ScheduleWeek
- new_sch.PartitionId = sch_two.PartitionId
- new_sch.ScheduleType = sch_two.ScheduleType
- new_sch.ID = 0
- //删除原来的排班
- err := service.SaveSchTwo(sch, sch_two)
- //生成新的排班
- if err == nil {
- err2 := service.SaveSch(&new_sch)
-
- order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
- if order.ID > 0 {
- scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
- service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
- redis := service.RedisClient()
- key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
-
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- }
-
- orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
- if orderOne.ID > 0 {
- scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
- service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
- redis := service.RedisClient()
- key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- }
-
- if err2 == nil {
- //去除当天患者排班中重复数据,保留最后一条数据
- service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
- service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
- service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "覆盖成功",
- "new_sch": new_sch,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *DialysisAPIController) BatchCheckAdvice() {
-
- patient_id, _ := c.GetInt64("patient_id")
-
- advice_date, _ := c.GetInt64("advice_date")
-
- org_id := c.GetMobileAdminUserInfo().Org.Id
-
- creater := c.GetMobileAdminUserInfo().AdminUser.Id
-
- //查询是his系统还是血透系统
- _, configs := service.FindXTHisRecordByOrgId(org_id)
-
- //his客户
- if configs.IsOpen == 1 {
-
- adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
- for _, item := range adviceList {
- service.BatchCheckHisAdvice(item.ID, creater)
- }
- projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
- for _, item := range projectList {
- service.BatchCheckProject(item.ID, creater)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "adviceList": adviceList,
- "projectList": projectList,
- })
-
- }
-
- if configs.IsOpen != 1 {
-
- adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
-
- for _, item := range adviceList {
- service.BatchAdviceList(item.ID, creater)
- }
- projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
- for _, item := range projectList {
- service.BatchCheckProject(item.ID, creater)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "adviceList": adviceList,
- "projectList": projectList,
- })
- }
-
- return
- }
-
- func (c *DialysisAPIController) GetAllMobileDrugList() {
-
- org_id := c.GetMobileAdminUserInfo().Org.Id
-
- drugList, _ := service.GetAllDrugList(org_id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "drugList": drugList,
- })
- }
-
- func (c *DialysisAPIController) SaveLongMobileAdvice() {
-
- org_id := c.GetMobileAdminUserInfo().Org.Id
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
- utils.ErrorLog("advice_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceType := int64(dataBody["advice_type"].(float64))
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startTime2, _ := dataBody["start_time"].(string)
- time_arr := strings.Split(startTime2, " ")
- if len(time_arr) > 0 {
- startTime2 = time_arr[0]
- }
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice_date, _ := dataBody["advice_date"].(string)
-
- var advicedateunix int64
- if len(advice_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advicedateunix = theTime.Unix()
- }
-
- adviceDate := startTime2
- if len(adviceDate) == 0 {
- utils.ErrorLog("len(adviceDate) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- AdviceDate := advicedateunix
- RecordDate := advicedateunix
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime, _ := dataBody["start_time"].(string)
-
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- StartTime := theTime.Unix()
-
- advice_name, _ := dataBody["advice_name"].(string)
-
- advice_desc, _ := dataBody["advice_desc"].(string)
-
- delivery_way, _ := dataBody["delivery_way"].(string)
-
- execution_frequency, _ := dataBody["execution_frequency"].(string)
-
- frequency_type := int64(dataBody["frequency_type"].(float64))
-
- frequency_week, _ := dataBody["frequency_week"].(string)
-
- prescribing_number := dataBody["prescribing_number"].(float64)
-
- prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
-
- remark := dataBody["remark"].(string)
-
- single_dose := dataBody["single_dose"].(float64)
-
- single_dose_unit := dataBody["single_dose_unit"].(string)
-
- patient_id := int64(dataBody["patient_id"].(float64))
-
- day_count := int64(dataBody["day_count"].(float64))
-
- groupNo := int64(dataBody["group_no"].(float64))
- advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
-
- adviceLast, _ := service.GetLastLongAdviceList(org_id)
-
- if groupNo <= 0 {
- group := service.GetMaxAdviceGroupID(org_id)
- groupNo = group + 1
- }
- var template_id = ""
- adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
- template_id = "M" + adviceLastId
- advice := models.DoctorAdvice{
- UserOrgId: org_id,
- PatientId: patient_id,
- AdviceType: adviceType,
- AdviceDate: AdviceDate,
- StartTime: StartTime,
- AdviceName: advice_name,
- AdviceDesc: advice_desc,
- ReminderDate: 0,
- SingleDose: single_dose,
- SingleDoseUnit: single_dose_unit,
- DrugSpec: 0,
- DrugSpecUnit: "",
- PrescribingNumber: prescribing_number,
- PrescribingNumberUnit: prescribing_number_unit,
- DeliveryWay: delivery_way,
- ExecutionFrequency: execution_frequency,
- AdviceDoctor: advice_doctor,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: 0,
- AdviceAffirm: "",
- Remark: remark,
- StopTime: 0,
- StopReason: "",
- StopDoctor: 0,
- StopState: 0,
- ParentId: 0,
- ExecutionTime: 0,
- ExecutionStaff: 0,
- ExecutionState: 0,
- Checker: 0,
- RecordDate: RecordDate,
- DialysisOrderId: 0,
- CheckTime: 0,
- CheckState: 0,
- AdviceId: 0,
- RemindType: 0,
- FrequencyType: frequency_type,
- DayCount: day_count,
- WeekDay: frequency_week,
- ChildDoctorAdvice: nil,
- TemplateId: template_id,
- Modifier: 0,
- IsCheck: 0,
- Way: 0,
- DrugId: 0,
- DrugNameId: 0,
- IsMedicine: 0,
- PushStartTime: 0,
- IsSettle: 0,
- IsPrescription: 0,
- GroupNo: groupNo,
- }
-
- service.CreateMobileAdivce(advice)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功!",
- })
-
- }
-
- func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
-
- patient_id, _ := c.GetInt64("patient_id")
-
- org_id := c.GetMobileAdminUserInfo().Org.Id
- app_id := c.GetMobileAdminUserInfo().App.Id
- adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
- adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "adviceList": adviceList,
- "adminRoles": adminRoles,
- })
- }
-
- func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
-
- org_id := c.GetMobileAdminUserInfo().Org.Id
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startTime2, _ := dataBody["start_time"].(string)
- time_arr := strings.Split(startTime2, " ")
- if len(time_arr) > 0 {
- startTime2 = time_arr[0]
- }
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice_date, _ := dataBody["advice_date"].(string)
-
- var advicedateunix int64
- if len(advice_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advicedateunix = theTime.Unix()
- }
-
- adviceDate := startTime2
- if len(adviceDate) == 0 {
- utils.ErrorLog("len(adviceDate) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- AdviceDate := advicedateunix
- RecordDate := advicedateunix
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime, _ := dataBody["start_time"].(string)
-
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- StartTime := theTime.Unix()
-
- advice_name, _ := dataBody["advice_name"].(string)
-
- advice_desc, _ := dataBody["advice_desc"].(string)
-
- delivery_way, _ := dataBody["delivery_way"].(string)
-
- execution_frequency, _ := dataBody["execution_frequency"].(string)
-
- prescribing_number := dataBody["prescribing_number"].(float64)
-
- prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
-
- remark := dataBody["remark"].(string)
-
- single_dose := dataBody["single_dose"].(float64)
-
- single_dose_unit := dataBody["single_dose_unit"].(string)
-
- patient_id := int64(dataBody["patient_id"].(float64))
-
- groupNo := int64(dataBody["group_no"].(float64))
-
- parent_id := int64(dataBody["parent_id"].(float64))
-
- advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
- advice := models.XtDoctorAdviceOne{
- UserOrgId: org_id,
- PatientId: patient_id,
- AdviceType: 1,
- AdviceDate: AdviceDate,
- StartTime: StartTime,
- AdviceName: advice_name,
- AdviceDesc: advice_desc,
- ReminderDate: 0,
- SingleDose: single_dose,
- SingleDoseUnit: single_dose_unit,
- PrescribingNumber: prescribing_number,
- PrescribingNumberUnit: prescribing_number_unit,
- DeliveryWay: delivery_way,
- ExecutionFrequency: execution_frequency,
- AdviceDoctor: advice_doctor,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- AdviceAffirm: "",
- Remark: remark,
- StopTime: 0,
- StopReason: "",
- StopDoctor: 0,
- StopState: 0,
- ParentId: parent_id,
- ExecutionTime: 0,
- ExecutionStaff: 0,
- ExecutionState: 0,
- Checker: 0,
- RecordDate: RecordDate,
- DialysisOrderId: 0,
- CheckTime: 0,
- CheckState: 0,
- DrugSpec: 0,
- DrugSpecUnit: "",
- Groupno: groupNo,
- RemindType: 0,
- FrequencyType: 0,
- DayCount: 0,
- WeekDay: "",
- TemplateId: "",
- Modifier: 0,
- }
-
- service.CreateMobileAdivceOne(advice)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功!",
- })
- }
-
- func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
-
- id, _ := c.GetInt64("id")
-
- service.DeleteSelfAdviceSubAdvice(id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功!",
- })
- }
-
- func (c *DialysisAPIController) GetEditAdviceAction() {
-
- id, _ := c.GetInt64("id")
- org_id := c.GetMobileAdminUserInfo().Org.Id
- advice, _ := service.GetEditAdviceActionList(id, org_id)
- drugList, _ := service.GetAllDrugList(org_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "advice": advice,
- "drugList": drugList,
- })
- }
-
- func (c *DialysisAPIController) UpdateLongMobileAdvice() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startTime2, _ := dataBody["start_time"].(string)
- time_arr := strings.Split(startTime2, " ")
- if len(time_arr) > 0 {
- startTime2 = time_arr[0]
- }
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice_date, _ := dataBody["advice_date"].(string)
-
- var advicedateunix int64
- if len(advice_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advicedateunix = theTime.Unix()
- }
-
- adviceDate := startTime2
- if len(adviceDate) == 0 {
- utils.ErrorLog("len(adviceDate) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- AdviceDate := advicedateunix
- RecordDate := advicedateunix
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime, _ := dataBody["start_time"].(string)
-
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- StartTime := theTime.Unix()
-
- advice_name, _ := dataBody["advice_name"].(string)
-
- advice_desc, _ := dataBody["advice_desc"].(string)
-
- delivery_way, _ := dataBody["delivery_way"].(string)
-
- execution_frequency, _ := dataBody["execution_frequency"].(string)
-
- prescribing_number := dataBody["prescribing_number"].(float64)
-
- prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
-
- remark := dataBody["remark"].(string)
-
- single_dose := dataBody["single_dose"].(float64)
-
- single_dose_unit := dataBody["single_dose_unit"].(string)
-
- id := int64(dataBody["id"].(float64))
-
- frequency_type := int64(dataBody["frequency_type"].(float64))
-
- frequency_week, _ := dataBody["frequency_week"].(string)
-
- day_count := int64(dataBody["day_count"].(float64))
-
- advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
- advice := models.XtDoctorAdviceOne{
- AdviceDate: AdviceDate,
- StartTime: StartTime,
- AdviceName: advice_name,
- AdviceDesc: advice_desc,
- SingleDose: single_dose,
- SingleDoseUnit: single_dose_unit,
- PrescribingNumber: prescribing_number,
- PrescribingNumberUnit: prescribing_number_unit,
- DeliveryWay: delivery_way,
- ExecutionFrequency: execution_frequency,
- AdviceDoctor: advice_doctor,
- Remark: remark,
- RecordDate: RecordDate,
- FrequencyType: frequency_type,
- DayCount: day_count,
- WeekDay: frequency_week,
- }
-
- service.UpdateMobileDoctorAdviceByIdOne(id, advice)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "advice": advice,
- })
- }
-
- func (c *DialysisAPIController) UpdateEditDrugOrder() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startTime2, _ := dataBody["start_time"].(string)
- time_arr := strings.Split(startTime2, " ")
- if len(time_arr) > 0 {
- startTime2 = time_arr[0]
- }
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice_date, _ := dataBody["advice_date"].(string)
-
- var advicedateunix int64
- if len(advice_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advicedateunix = theTime.Unix()
- }
-
- adviceDate := startTime2
- if len(adviceDate) == 0 {
- utils.ErrorLog("len(adviceDate) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- AdviceDate := advicedateunix
- RecordDate := advicedateunix
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime, _ := dataBody["start_time"].(string)
-
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- StartTime := theTime.Unix()
-
- advice_name, _ := dataBody["advice_name"].(string)
-
- advice_desc, _ := dataBody["advice_desc"].(string)
-
- delivery_way, _ := dataBody["delivery_way"].(string)
-
- execution_frequency, _ := dataBody["execution_frequency"].(string)
-
- prescribing_number := dataBody["prescribing_number"].(float64)
-
- prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
-
- remark := dataBody["remark"].(string)
-
- single_dose := dataBody["single_dose"].(float64)
-
- single_dose_unit := dataBody["single_dose_unit"].(string)
-
- id := int64(dataBody["id"].(float64))
-
- advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
- advice := models.XtDoctorAdviceOne{
- AdviceDate: AdviceDate,
- StartTime: StartTime,
- AdviceName: advice_name,
- AdviceDesc: advice_desc,
- SingleDose: single_dose,
- SingleDoseUnit: single_dose_unit,
- PrescribingNumber: prescribing_number,
- PrescribingNumberUnit: prescribing_number_unit,
- DeliveryWay: delivery_way,
- ExecutionFrequency: execution_frequency,
- AdviceDoctor: advice_doctor,
- Remark: remark,
- RecordDate: RecordDate,
- }
-
- service.UpdateMobileDoctorAdviceById(id, advice)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "advice": advice,
- })
- }
-
- func (c *DialysisAPIController) SaveLongAdviceTemplate() {
-
- dataBody := make(map[string]interface{}, 0)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startTime2, _ := dataBody["start_time"].(string)
- time_arr := strings.Split(startTime2, " ")
- if len(time_arr) > 0 {
- startTime2 = time_arr[0]
- }
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice_date, _ := dataBody["advice_date"].(string)
-
- var advicedateunix int64
- if len(advice_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
- if err != nil {
- fmt.Println(err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advicedateunix = theTime.Unix()
- }
-
- adviceDate := startTime2
- if len(adviceDate) == 0 {
- utils.ErrorLog("len(adviceDate) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- RecordDate := advicedateunix
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime, _ := dataBody["start_time"].(string)
-
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- StartTime := theTime.Unix()
-
- patient_id := int64(dataBody["patient_id"].(float64))
-
- group_no := int64(dataBody["group_no"].(float64))
-
- org_id := c.GetMobileAdminUserInfo().Org.Id
-
- advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
-
- if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
- utils.ErrorLog("advices")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceNames := dataBody["advices"].([]interface{})
-
- var advices []*models.GroupAdvice
- for _, adviceNameMap := range adviceNames {
- var advice models.GroupAdvice
- adviceNameM := adviceNameMap.(map[string]interface{})
- if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceName, _ := adviceNameM["advice_name"].(string)
-
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice.AdviceName = adviceName
-
- if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
-
- if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
- adviceDesc, _ := adviceNameM["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- }
-
- if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
- drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
-
- if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
- if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
- singleDose := adviceNameM["single_dose"].(float64)
- advice.SingleDose = singleDose
- }
-
- if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
- if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
- tmp := adviceNameM["single_dose_unit"].(float64)
- singleDoseUnit := service.TypeConversion(tmp)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
- if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
- prescribingNumber := adviceNameM["prescribing_number"].(float64)
- advice.PrescribingNumber = prescribingNumber
- }
-
- if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
- deliveryWay, _ := adviceNameM["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
-
- if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- remark, _ := adviceNameM["remark"].(string)
-
- advice.Remark = remark
-
- advice.AdviceType = 1
-
- advice.StartTime = StartTime
- advice.RecordDate = RecordDate
-
- advice.PatientId = patient_id
-
- advice.UserOrgId = org_id
-
- advice.AdviceDoctor = advice_doctor
-
- advices = append(advices, &advice)
- }
-
- newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "advice": newAdvices,
- })
- }
|