patient_api_controller.go 238KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math"
  6. "strings"
  7. "XT_New/enums"
  8. "XT_New/models"
  9. "XT_New/service"
  10. "XT_New/utils"
  11. // "fmt"
  12. "reflect"
  13. "strconv"
  14. "time"
  15. )
  16. type PatientApiController struct {
  17. MobileBaseAPIAuthController
  18. }
  19. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  20. id, _ := c.GetInt64("patient", 0)
  21. if id <= 0 {
  22. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  23. return
  24. }
  25. adminUserInfo := c.GetMobileAdminUserInfo()
  26. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  27. if patient.ID == 0 {
  28. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  29. return
  30. }
  31. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  32. if err != nil {
  33. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  34. return
  35. }
  36. if Registrars != nil {
  37. patient.Registrars = Registrars.Name
  38. }
  39. c.ServeSuccessJSON(map[string]interface{}{
  40. "patient": patient,
  41. })
  42. return
  43. }
  44. func (c *PatientApiController) CreateDialysisSolution() {
  45. id, _ := c.GetInt64("patient", 0)
  46. if id <= 0 {
  47. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  48. return
  49. }
  50. adminUserInfo := c.GetMobileAdminUserInfo()
  51. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  52. if patient.ID == 0 {
  53. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  54. return
  55. }
  56. //根据路由来做权限
  57. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  58. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  59. //if template.TemplateId == 2 || template.TemplateId == 6 {
  60. // if appRole.UserType == 3 {
  61. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  62. // if getPermissionErr != nil {
  63. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  64. // return
  65. // } else if headNursePermission == nil {
  66. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  67. // return
  68. // }
  69. // }
  70. //}
  71. var solution models.DialysisSolution
  72. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  73. if code > 0 {
  74. c.ServeFailJSONWithSGJErrorCode(code)
  75. return
  76. }
  77. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  78. solution.Doctor = adminUserInfo.AdminUser.Id
  79. solution.Status = 1
  80. solution.PatientId = id
  81. solution.CreatedTime = time.Now().Unix()
  82. solution.UserOrgId = adminUserInfo.Org.Id
  83. solution.UpdatedTime = time.Now().Unix()
  84. solution.SubName = ""
  85. solution.ParentId = 0
  86. err := service.CreatePatientDialysisSolution(&solution)
  87. if err != nil {
  88. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  89. return
  90. }
  91. c.ServeSuccessJSON(map[string]interface{}{
  92. "msg": "ok",
  93. "solution": solution,
  94. })
  95. return
  96. }
  97. func (c *PatientApiController) EditDialysisSolution() {
  98. id, _ := c.GetInt64("id", 0)
  99. if id <= 0 {
  100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  101. return
  102. }
  103. adminUserInfo := c.GetMobileAdminUserInfo()
  104. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  105. if solution.ID == 0 {
  106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  107. return
  108. }
  109. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  110. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  111. // if getPermissionErr != nil {
  112. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  113. // return
  114. // } else if headNursePermission == nil {
  115. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  116. // return
  117. // }
  118. //}
  119. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  120. if code > 0 {
  121. c.ServeFailJSONWithSGJErrorCode(code)
  122. return
  123. }
  124. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  125. solution.Doctor = adminUserInfo.AdminUser.Id
  126. solution.Status = 1
  127. // solution.PatientId = id
  128. // solution.CreatedTime = time.Now().Unix()
  129. // solution.UserOrgId = adminUserInfo.Org.Id
  130. solution.UpdatedTime = time.Now().Unix()
  131. // solution.SubName = ""
  132. // solution.ParentId = 0
  133. err := service.UpdatePatientDialysisSolution(&solution)
  134. if err != nil {
  135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  136. return
  137. }
  138. c.ServeSuccessJSON(map[string]interface{}{
  139. "msg": "ok",
  140. "solution": solution,
  141. })
  142. return
  143. }
  144. func (c *PatientApiController) CreateDoctorAdvice() {
  145. patient, _ := c.GetInt64("id", 0)
  146. if patient <= 0 {
  147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  148. return
  149. }
  150. adminUserInfo := c.GetMobileAdminUserInfo()
  151. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  152. if patientInfo.ID == 0 {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  154. return
  155. }
  156. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  157. //if appRole.UserType == 3{
  158. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  159. // return
  160. //}
  161. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  162. //
  163. //if appRole.UserType == 3 {
  164. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  165. // if getPermissionErr != nil {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  167. // return
  168. // } else if headNursePermission == nil {
  169. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  170. // return
  171. // }
  172. //}
  173. var advice models.DoctorAdvice
  174. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  175. if code > 0 {
  176. c.ServeFailJSONWithSGJErrorCode(code)
  177. return
  178. }
  179. if advice.ParentId > 0 {
  180. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  181. if old.ID == 0 || old.PatientId != patient {
  182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  183. return
  184. }
  185. if old.StopState == 1 || old.ExecutionState == 1 {
  186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  187. return
  188. }
  189. if old.ParentId > 0 {
  190. advice.ParentId = old.ParentId
  191. }
  192. advice.StartTime = old.StartTime
  193. advice.AdviceDoctor = old.AdviceDoctor
  194. advice.DeliveryWay = old.DeliveryWay
  195. advice.ExecutionFrequency = old.ExecutionFrequency
  196. advice.GroupNo = old.GroupNo
  197. }
  198. advice.Status = 1
  199. advice.CreatedTime = time.Now().Unix()
  200. advice.UpdatedTime = time.Now().Unix()
  201. advice.StopState = 2
  202. advice.ExecutionState = 2
  203. advice.UserOrgId = adminUserInfo.Org.Id
  204. advice.PatientId = patient
  205. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  206. err := service.CreateDoctorAdvice(&advice)
  207. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  208. redis := service.RedisClient()
  209. defer redis.Close()
  210. redis.Set(key, "", time.Second)
  211. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  212. redis.Set(keyOne, "", time.Second)
  213. if err != nil {
  214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  215. return
  216. }
  217. c.ServeSuccessJSON(map[string]interface{}{
  218. "msg": "ok",
  219. "advice": advice,
  220. })
  221. return
  222. }
  223. func (c *PatientApiController) EditDoctorAdvice() {
  224. id, _ := c.GetInt64("id", 0)
  225. patient_id, _ := c.GetInt64("patient_id")
  226. doc_advice_date, _ := c.GetInt64("advice_date")
  227. if id <= 0 {
  228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  229. return
  230. }
  231. redis := service.RedisClient()
  232. adminUserInfo := c.GetMobileAdminUserInfo()
  233. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  234. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  235. //
  236. //if appRole.UserType == 3 {
  237. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  238. // if getPermissionErr != nil {
  239. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  240. // return
  241. // } else if headNursePermission == nil {
  242. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  243. // return
  244. // }
  245. //}
  246. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  247. if advice.ID == 0 {
  248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  249. return
  250. }
  251. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  252. if code > 0 {
  253. c.ServeFailJSONWithSGJErrorCode(code)
  254. return
  255. }
  256. advice.Status = 1
  257. advice.UpdatedTime = time.Now().Unix()
  258. advice.UserOrgId = adminUserInfo.Org.Id
  259. advice.Modifier = adminUserInfo.AdminUser.Id
  260. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  261. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  262. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  263. var err error
  264. var isChangeGroup bool
  265. if advice.ParentId == 0 {
  266. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  267. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  268. if len(adviceSlice) == 1 {
  269. // 查询信息规挡的设置天数
  270. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  271. if infor.ID > 0 && infor.WeekDay > 0 {
  272. var cha_time int64
  273. timeNowStr := time.Now().Format("2006-01-02")
  274. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  275. //今日的日期减去设置的日期
  276. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  277. if cha_time >= sourceAdvice.AdviceDate {
  278. //查询审核是否允许
  279. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id, 4)
  280. //申请状态不允许的情况 拒绝修改
  281. if infor.ApplicationStatus != 1 {
  282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  283. return
  284. }
  285. }
  286. }
  287. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  288. if advice.StartTime == sourceAdvice.StartTime {
  289. err = service.UpdateDoctorAdvice(&advice)
  290. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  291. defer redis.Close()
  292. redis.Set(key, "", time.Second)
  293. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  294. redis.Set(keyOne, "", time.Second)
  295. isChangeGroup = false
  296. } else {
  297. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  298. isChangeGroup = false
  299. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  300. defer redis.Close()
  301. redis.Set(key, "", time.Second)
  302. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  303. redis.Set(keyOne, "", time.Second)
  304. }
  305. } else if len(adviceSlice) > 1 {
  306. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  307. if infor.ID > 0 {
  308. var cha_time int64
  309. timeNowStr := time.Now().Format("2006-01-02")
  310. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  311. //今日的日期减去设置的日期
  312. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  313. if cha_time >= sourceAdvice.AdviceDate {
  314. //查询审核是否允许
  315. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id, 4)
  316. //申请状态不允许的情况 拒绝修改
  317. if infor.ApplicationStatus != 1 {
  318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  319. return
  320. }
  321. }
  322. }
  323. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  324. if advice.StartTime == sourceAdvice.StartTime {
  325. err = service.UpdateDoctorAdvice(&advice)
  326. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  327. defer redis.Close()
  328. redis.Set(key, "", time.Second)
  329. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  330. redis.Set(keyOne, "", time.Second)
  331. isChangeGroup = false
  332. } else {
  333. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  334. gruopNo = gruopNo + 1
  335. advice.GroupNo = gruopNo
  336. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  337. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  338. defer redis.Close()
  339. redis.Set(key, "", time.Second)
  340. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  341. redis.Set(keyOne, "", time.Second)
  342. isChangeGroup = true
  343. }
  344. }
  345. } else {
  346. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  347. if infor.ID > 0 {
  348. var cha_time int64
  349. timeNowStr := time.Now().Format("2006-01-02")
  350. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  351. //今日的日期减去设置的日期
  352. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  353. if cha_time >= advice.AdviceDate {
  354. //查询审核是否允许
  355. infor, _ := service.GetDialysisInformationByRecordDate(id, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  356. //申请状态不允许的情况 拒绝修改
  357. if infor.ApplicationStatus != 1 {
  358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  359. return
  360. }
  361. }
  362. }
  363. isChangeGroup = false
  364. err = service.UpdateDoctorAdvice(&advice)
  365. redis := service.RedisClient()
  366. defer redis.Close()
  367. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  368. redis.Set(key, "", time.Second)
  369. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  370. redis.Set(keyOne, "", time.Second)
  371. }
  372. if err != nil {
  373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  374. return
  375. }
  376. if !isChangeGroup {
  377. c.ServeSuccessJSON(map[string]interface{}{
  378. "msg": "ok",
  379. "advice": advice,
  380. "isChange": isChangeGroup, //方便前端处理数据
  381. })
  382. } else {
  383. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  384. if err != nil {
  385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  386. return
  387. }
  388. c.ServeSuccessJSON(map[string]interface{}{
  389. "msg": "ok",
  390. "advice": newGroupAdvice,
  391. "isChange": isChangeGroup, //方便前端处理数据
  392. })
  393. }
  394. return
  395. }
  396. func (c *PatientApiController) StopDoctorAdvice() {
  397. id, _ := c.GetInt64("id", 0)
  398. if id <= 0 {
  399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  400. return
  401. }
  402. adminUserInfo := c.GetMobileAdminUserInfo()
  403. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  404. if advice.ID == 0 {
  405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  406. return
  407. }
  408. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  409. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  410. // return
  411. //}
  412. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  413. //
  414. //if appRole.UserType == 3 {
  415. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  416. // if getPermissionErr != nil {
  417. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  418. // return
  419. // } else if headNursePermission == nil {
  420. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  421. // return
  422. // }
  423. //}
  424. if advice.StopState == 1 {
  425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  426. return
  427. }
  428. dataBody := make(map[string]interface{}, 0)
  429. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  430. if err != nil {
  431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  432. return
  433. }
  434. timeLayout := "2006-01-02"
  435. loc, _ := time.LoadLocation("Local")
  436. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  437. utils.ErrorLog("stop_time")
  438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  439. return
  440. }
  441. stopTime, _ := dataBody["stop_time"].(string)
  442. if len(stopTime) == 0 {
  443. utils.ErrorLog("len(stop_time) == 0")
  444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  445. return
  446. }
  447. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  448. if err != nil {
  449. utils.ErrorLog(err.Error())
  450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  451. return
  452. }
  453. advice.StopTime = theTime.Unix()
  454. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  455. utils.ErrorLog("stop_reason")
  456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  457. return
  458. }
  459. stopReason, _ := dataBody["stop_reason"].(string)
  460. if len(stopReason) == 0 {
  461. utils.ErrorLog("len(stop_reason) == 0")
  462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  463. return
  464. }
  465. advice.StopReason = stopReason
  466. advice.Status = 1
  467. advice.UpdatedTime = time.Now().Unix()
  468. advice.StopDoctor = adminUserInfo.AdminUser.Id
  469. advice.StopState = 1
  470. advice.StopTime = time.Now().Unix()
  471. advice.Modifier = adminUserInfo.AdminUser.Id
  472. err = service.StopDoctorAdvice(&advice)
  473. if err != nil {
  474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  475. return
  476. }
  477. c.ServeSuccessJSON(map[string]interface{}{
  478. "msg": "ok",
  479. "advice": advice,
  480. })
  481. return
  482. }
  483. func (c *PatientApiController) DeleteDoctorAdvice() {
  484. id, _ := c.GetInt64("id", 0)
  485. if id <= 0 {
  486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  487. return
  488. }
  489. adminUserInfo := c.GetMobileAdminUserInfo()
  490. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  491. if advice.ID == 0 {
  492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  493. return
  494. }
  495. //自备药
  496. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  497. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  498. //查询库存是否是自备药
  499. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  500. if selfBasedrug.IsSelfDrug == 1 {
  501. creater := adminUserInfo.AdminUser.Id
  502. //退库
  503. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  504. }
  505. }
  506. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  507. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  508. // return
  509. //}
  510. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  511. //
  512. //if appRole.UserType == 3 {
  513. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  514. // if getPermissionErr != nil {
  515. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  516. // return
  517. // } else if headNursePermission == nil {
  518. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  519. // return
  520. // }
  521. //}
  522. advice.UpdatedTime = time.Now().Unix()
  523. advice.Status = 0
  524. advice.Modifier = adminUserInfo.AdminUser.Id
  525. err := service.DeleteDoctorAdvice(&advice)
  526. if err != nil {
  527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  528. return
  529. }
  530. c.ServeSuccessJSON(map[string]interface{}{
  531. "msg": "ok",
  532. })
  533. return
  534. }
  535. func (c *PatientApiController) ExecDoctorAdvice() {
  536. execution_time := c.GetString("execution_time")
  537. origin, _ := c.GetInt64("origin", 0)
  538. groupno, _ := c.GetInt64("groupno", -1)
  539. record_date, _ := c.GetInt64("record_date")
  540. if origin != 2 {
  541. adminUserInfo := c.GetMobileAdminUserInfo()
  542. execution_staff := adminUserInfo.AdminUser.Id
  543. var ids []string
  544. advice_ids := c.GetString("advice_id")
  545. if groupno == 0 {
  546. ids = strings.Split(advice_ids, ",")
  547. }
  548. if groupno < 0 {
  549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  550. return
  551. }
  552. if len(execution_time) <= 0 {
  553. utils.ErrorLog("execution_time")
  554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  555. return
  556. }
  557. timeLayout2 := "2006-01-02 15:04:05"
  558. loc, _ := time.LoadLocation("Local")
  559. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  560. if errs != nil {
  561. utils.ErrorLog(errs.Error())
  562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  563. return
  564. }
  565. var advice models.DoctorAdvice
  566. if groupno > 0 {
  567. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  568. for _, item := range advices {
  569. //自备药
  570. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  571. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  572. //查询库存是否
  573. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  574. if selfBasedrug.IsSelfDrug == 1 {
  575. selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
  576. var prescribing_number_total_one int64
  577. //判断单位是否相等
  578. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  579. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  580. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  581. //转化为最小单位
  582. prescribing_number_total_one = count * selfBasedrug.MinNumber
  583. }
  584. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  585. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  586. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  587. prescribing_number_total_one = count
  588. }
  589. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  590. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  591. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  592. prescribing_number_total_one = count
  593. }
  594. if prescribing_number_total_one > selfDrugStockCount.FlushCount {
  595. c.ServeSuccessJSON(map[string]interface{}{
  596. "msg": "2",
  597. "advice": advice,
  598. "ids": ids,
  599. })
  600. return
  601. }
  602. }
  603. }
  604. //恒泰中医院
  605. if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
  606. if item.DrugId == 0 || item.DrugNameId == 0 {
  607. //从字典里面查找
  608. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  609. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  610. }
  611. }
  612. if item.ExecutionState == 2 {
  613. advice = item
  614. }
  615. //记录日志
  616. byterequest, _ := json.Marshal(item)
  617. adviceLog := models.XtDoctorAdviceLog{
  618. UserOrgId: item.UserOrgId,
  619. PatientId: item.PatientId,
  620. AdminUserId: adminUserInfo.AdminUser.Id,
  621. Module: 2,
  622. ErrLog: string(byterequest),
  623. Status: 1,
  624. Ctime: time.Now().Unix(),
  625. Mtime: 0,
  626. Source: "手机端执行医嘱",
  627. RecordDate: item.AdviceDate,
  628. }
  629. service.CreateDoctorAdviceLog(adviceLog)
  630. }
  631. } else {
  632. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  633. for _, item := range advices {
  634. //自备药
  635. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  636. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  637. //查询库存是否
  638. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  639. if selfBasedrug.IsSelfDrug == 1 {
  640. selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
  641. var prescribing_number_total_one int64
  642. //判断单位是否相等
  643. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  644. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  645. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  646. //转化为最小单位
  647. prescribing_number_total_one = count * selfBasedrug.MinNumber
  648. }
  649. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  650. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  651. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  652. prescribing_number_total_one = count
  653. }
  654. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  655. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  656. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  657. prescribing_number_total_one = count
  658. }
  659. if prescribing_number_total_one > selfDrugStockCount.FlushCount {
  660. c.ServeSuccessJSON(map[string]interface{}{
  661. "msg": "2",
  662. "advice": advice,
  663. "ids": ids,
  664. })
  665. return
  666. }
  667. }
  668. }
  669. //恒泰中医院
  670. if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
  671. if item.DrugId == 0 || item.DrugNameId == 0 {
  672. //从字典里面查找
  673. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  674. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  675. }
  676. }
  677. if item.ExecutionState == 2 {
  678. advice = item
  679. }
  680. }
  681. }
  682. if advice.ExecutionState == 1 {
  683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  684. return
  685. }
  686. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  688. return
  689. }
  690. //针对普宁
  691. if adminUserInfo.Org.Id != 10599 {
  692. if advice.StartTime > theTime.Unix() {
  693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  694. return
  695. }
  696. }
  697. advices := models.DoctorAdvice{
  698. ExecutionStaff: execution_staff,
  699. ExecutionTime: theTime.Unix(),
  700. UpdatedTime: time.Now().Unix(),
  701. }
  702. var err error
  703. if groupno > 0 {
  704. // 查询信息规挡的设置天数
  705. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  706. if infor.ID > 0 && infor.WeekDay > 0 {
  707. var cha_time int64
  708. timeNowStr := time.Now().Format("2006-01-02")
  709. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  710. //今日的日期减去设置的日期
  711. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  712. if cha_time >= record_date {
  713. //查询审核是否允许
  714. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  715. //申请状态不允许的情况 拒绝修改
  716. if infor.ApplicationStatus != 1 {
  717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  718. return
  719. }
  720. }
  721. }
  722. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  723. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  724. redis := service.RedisClient()
  725. //清空key 值
  726. redis.Set(key, "", time.Second)
  727. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  728. redis.Set(keyTwo, "", time.Second)
  729. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  730. redis.Set(keyThree, "", time.Second)
  731. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  732. theTime := toTime.Format("2006-01-02")
  733. fmt.Println("theTIME", theTime)
  734. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  735. redis.Set(keyFour, "", time.Second)
  736. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  737. redis.Set(keyFive, "", time.Second)
  738. defer redis.Close()
  739. } else {
  740. // 查询信息规挡的设置天数
  741. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  742. if infor.ID > 0 {
  743. var cha_time int64
  744. timeNowStr := time.Now().Format("2006-01-02")
  745. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  746. //今日的日期减去设置的日期
  747. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  748. if cha_time >= record_date {
  749. //查询审核是否允许
  750. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  751. //申请状态不允许的情况 拒绝修改
  752. if infor.ApplicationStatus != 1 {
  753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  754. return
  755. }
  756. }
  757. }
  758. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  759. //记录日志
  760. byterequest, _ := json.Marshal(advice)
  761. adviceLog := models.XtDoctorAdviceLog{
  762. UserOrgId: advice.UserOrgId,
  763. PatientId: advice.PatientId,
  764. AdminUserId: adminUserInfo.AdminUser.Id,
  765. Module: 2,
  766. ErrLog: string(byterequest),
  767. Status: 1,
  768. Ctime: time.Now().Unix(),
  769. Mtime: 0,
  770. Source: "手机端执行医嘱",
  771. RecordDate: advices.RecordDate,
  772. }
  773. service.CreateDoctorAdviceLog(adviceLog)
  774. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  775. redis := service.RedisClient()
  776. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  777. redis.Set(keyTwo, "", time.Second)
  778. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  779. redis.Set(keyThree, "", time.Second)
  780. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  781. theTime := toTime.Format("2006-01-02")
  782. fmt.Println("theTIME", theTime)
  783. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  784. redis.Set(keyFour, "", time.Second)
  785. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  786. redis.Set(keySix, "", time.Second)
  787. defer redis.Close()
  788. //清空key 值
  789. redis.Set(key, "", time.Second)
  790. }
  791. if err != nil {
  792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  793. return
  794. }
  795. advice.ExecutionStaff = execution_staff
  796. advice.ExecutionTime = theTime.Unix()
  797. advice.ExecutionState = 1
  798. advice.Modifier = adminUserInfo.AdminUser.Id
  799. //处理出库相关逻辑
  800. //1.判断是否启用药品管理和自备药出库功能
  801. //药品管理信息
  802. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  803. //自备药信息
  804. //privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  805. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
  806. if drugStockConfig.IsOpen == 1 {
  807. if groupno > 0 {
  808. advices, _ := service.FindAllDoctorAdviceByGoroupNoTwety(adminUserInfo.Org.Id, groupno)
  809. if len(advices) > 0 {
  810. var total int64
  811. var prescribing_number_total int64
  812. //出库
  813. for _, item := range advices {
  814. if item.Way == 1 {
  815. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  816. //查询该药品的剩余库存
  817. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  818. //查询改药品信息
  819. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  820. //判断单位是否相等
  821. if medical.MaxUnit == item.PrescribingNumberUnit {
  822. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  823. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  824. //转化为最小单位
  825. total = list.Count * medical.MinNumber
  826. prescribing_number_total = count * medical.MinNumber
  827. }
  828. if medical.MinUnit == item.PrescribingNumberUnit {
  829. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  830. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  831. total = list.Count*medical.MinNumber + list.StockMinNumber
  832. prescribing_number_total = count
  833. }
  834. if medical.IsUse == 1 {
  835. c.ServeSuccessJSON(map[string]interface{}{
  836. "msg": "1",
  837. "advice": advice,
  838. "ids": ids,
  839. })
  840. return
  841. }
  842. if medical.IsUse != 1 {
  843. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  844. if advice.UserOrgId != 10278 {
  845. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  846. advice.ExecutionTime = 0
  847. advice.ExecutionState = 2
  848. advice.ExecutionStaff = 0
  849. }
  850. c.ServeSuccessJSON(map[string]interface{}{
  851. "msg": "3",
  852. "advice": advice,
  853. "ids": ids,
  854. })
  855. return
  856. }
  857. if prescribing_number_total > total {
  858. if advice.UserOrgId != 10278 {
  859. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  860. advice.ExecutionTime = 0
  861. advice.ExecutionState = 2
  862. advice.ExecutionStaff = 0
  863. }
  864. c.ServeSuccessJSON(map[string]interface{}{
  865. "msg": "2",
  866. "advice": advice,
  867. "ids": ids,
  868. })
  869. return
  870. }
  871. }
  872. //查询是否出库按钮开启
  873. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  874. if adviceSetting.IsAdviceOpen == 1 {
  875. //查询是否出库按钮开启
  876. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  877. //患者发药
  878. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  879. if prescriptionConfig.IsOpen == 1 {
  880. if medical.IsUse == 2 {
  881. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  882. //查询今日是否出库
  883. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  884. if drugOutInfo.ID == 0 {
  885. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  886. }
  887. }
  888. if pharmacyConfig.IsOpen != 1 {
  889. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  890. if drugOutInfo.ID == 0 {
  891. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  892. }
  893. }
  894. //更新字典里面的库存
  895. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  896. var sum_count int64
  897. for _, its := range stockInfo {
  898. if its.MaxUnit == medical.MaxUnit {
  899. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  900. }
  901. sum_count += its.StockMaxNumber + its.StockMinNumber
  902. }
  903. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  904. //剩余库存
  905. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  906. }
  907. }
  908. } else {
  909. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  910. if medical.IsUse == 2 {
  911. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  912. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  913. if drugOutInfo.ID == 0 {
  914. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  915. }
  916. }
  917. if pharmacyConfig.IsOpen != 1 {
  918. drugError := models.XtDrugError{
  919. ID: 0,
  920. UserOrgId: item.UserOrgId,
  921. DrugId: item.DrugId,
  922. RecordDate: item.AdviceDate,
  923. PatientId: item.PatientId,
  924. Remark: "恒泰中医院出库开始",
  925. Status: 1,
  926. Ctime: time.Now().Unix(),
  927. Mtime: 0,
  928. Prescribingnumber: item.PrescribingNumber,
  929. PrescribingNumberUnit: item.PrescribingNumberUnit,
  930. SumCount: 0,
  931. }
  932. service.CreateDrugError(drugError)
  933. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  934. if drugOutInfo.ID == 0 {
  935. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  936. }
  937. }
  938. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  939. var sum_count int64
  940. for _, its := range stockInfo {
  941. if its.MaxUnit == medical.MaxUnit {
  942. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  943. }
  944. sum_count += its.StockMaxNumber + its.StockMinNumber
  945. }
  946. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  947. //剩余库存
  948. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  949. }
  950. }
  951. }
  952. }
  953. }
  954. c.ServeSuccessJSON(map[string]interface{}{
  955. "msg": "1",
  956. "advice": advice,
  957. "ids": ids,
  958. })
  959. return
  960. } else {
  961. advices, _ := service.FindDoctorAdviceByIdsTwety(adminUserInfo.Org.Id, ids)
  962. if len(advices) > 0 {
  963. var total int64
  964. var prescribing_number_total int64
  965. for _, item := range advices {
  966. if item.Way == 1 {
  967. //查询改药品信息
  968. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  969. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  970. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  971. //查询该药品的剩余库存
  972. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  973. //判断单位是否相等
  974. if medical.MaxUnit == item.PrescribingNumberUnit {
  975. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  976. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  977. //转化为最小单位
  978. total = list.Count*medical.MinNumber + list.StockMinNumber
  979. prescribing_number_total = count * medical.MinNumber
  980. }
  981. if medical.MinUnit == item.PrescribingNumberUnit {
  982. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  983. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  984. total = list.Count*medical.MinNumber + list.StockMinNumber
  985. prescribing_number_total = count
  986. }
  987. if medical.IsUse == 1 {
  988. c.ServeSuccessJSON(map[string]interface{}{
  989. "msg": "1",
  990. "advice": advice,
  991. "ids": ids,
  992. })
  993. return
  994. }
  995. if medical.IsUse != 1 {
  996. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  997. if advice.UserOrgId != 10278 {
  998. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  999. advice.ExecutionTime = 0
  1000. advice.ExecutionState = 2
  1001. advice.ExecutionStaff = 0
  1002. }
  1003. c.ServeSuccessJSON(map[string]interface{}{
  1004. "msg": "3",
  1005. "advice": advice,
  1006. "ids": ids,
  1007. })
  1008. return
  1009. }
  1010. if prescribing_number_total > total {
  1011. if advice.UserOrgId != 10278 {
  1012. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  1013. advice.ExecutionTime = 0
  1014. advice.ExecutionState = 2
  1015. advice.ExecutionStaff = 0
  1016. }
  1017. c.ServeSuccessJSON(map[string]interface{}{
  1018. "msg": "2",
  1019. "advice": advice,
  1020. "ids": ids,
  1021. })
  1022. return
  1023. }
  1024. }
  1025. if medical.IsUse == 2 {
  1026. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1027. //查询今日是否出库
  1028. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1029. if drugOutInfo.ID == 0 {
  1030. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1031. }
  1032. }
  1033. if pharmacyConfig.IsOpen != 1 {
  1034. //查询今日是否出库
  1035. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1036. if drugOutInfo.ID == 0 {
  1037. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1038. }
  1039. }
  1040. //更新字典里面的库存
  1041. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1042. var sum_count int64
  1043. for _, its := range stockInfo {
  1044. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1045. if its.MaxUnit == baseDrug.MaxUnit {
  1046. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1047. }
  1048. sum_count += its.StockMaxNumber + its.StockMinNumber
  1049. }
  1050. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1051. //剩余库存
  1052. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1053. }
  1054. if medical.IsUse == 1 {
  1055. c.ServeSuccessJSON(map[string]interface{}{
  1056. "msg": "1",
  1057. "advice": advice,
  1058. "ids": ids,
  1059. })
  1060. return
  1061. }
  1062. }
  1063. }
  1064. }
  1065. c.ServeSuccessJSON(map[string]interface{}{
  1066. "msg": "1",
  1067. "advice": advice,
  1068. "ids": ids,
  1069. })
  1070. return
  1071. }
  1072. }
  1073. //if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  1074. // if groupno > 0 {
  1075. // advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1076. // for _, item := range advices {
  1077. //
  1078. // if item.ExecutionState == 1 && item.Way == 2 {
  1079. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1080. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1081. //
  1082. // timeStr := time.Now().Format("2006-01-02")
  1083. // timeArr := strings.Split(timeStr, "-")
  1084. // total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1085. //
  1086. // total = total + 1
  1087. // warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1088. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1089. // number = number + total
  1090. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1091. // //插入自备药出库单
  1092. // outStock := models.XtSelfOutStock{
  1093. // DrugName: item.AdviceName,
  1094. // DrugNameId: item.DrugNameId,
  1095. // DrugSpec: item.AdviceDesc,
  1096. // OutstoreNumber: count,
  1097. // AdminUserId: adminUserInfo.AdminUser.Id,
  1098. // StorckTime: item.AdviceDate,
  1099. // UserOrgId: adminUserInfo.Org.Id,
  1100. // CreatedTime: time.Now().Unix(),
  1101. // Status: 1,
  1102. // PatientId: item.PatientId,
  1103. // ExitMode: 2,
  1104. // MedicId: item.DrugId,
  1105. // StockOutNumber: warehousing_out_order,
  1106. // }
  1107. // //查询 该患者是否已出库
  1108. // out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1109. //
  1110. // if errcode == gorm.ErrRecordNotFound {
  1111. // service.CreateOutStock(&outStock)
  1112. // } else if errcode == nil {
  1113. // err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1114. // fmt.Println("err", err)
  1115. // }
  1116. // }
  1117. // }
  1118. // } else {
  1119. //
  1120. // advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1121. // for _, item := range advices {
  1122. //
  1123. // if item.ExecutionState == 1 && item.Way == 2 {
  1124. //
  1125. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1126. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1127. //
  1128. // timeStr := time.Now().Format("2006-01-02")
  1129. // timeArr := strings.Split(timeStr, "-")
  1130. // total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1131. //
  1132. // total = total + 1
  1133. // warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1134. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1135. // number = number + total
  1136. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1137. //
  1138. // //插入自备药出库单
  1139. // outStock := models.XtSelfOutStock{
  1140. // DrugName: item.AdviceName,
  1141. // DrugNameId: item.DrugNameId,
  1142. // DrugSpec: item.AdviceDesc,
  1143. // OutstoreNumber: count,
  1144. // AdminUserId: adminUserInfo.AdminUser.Id,
  1145. // StorckTime: item.AdviceDate,
  1146. // UserOrgId: adminUserInfo.Org.Id,
  1147. // CreatedTime: time.Now().Unix(),
  1148. // Status: 1,
  1149. // PatientId: item.PatientId,
  1150. // ExitMode: 2,
  1151. // MedicId: item.DrugId,
  1152. // StockOutNumber: warehousing_out_order,
  1153. // }
  1154. //
  1155. // //查询 该患者是否已出库
  1156. // out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1157. //
  1158. // if errcode == gorm.ErrRecordNotFound {
  1159. // service.CreateOutStock(&outStock)
  1160. // } else if errcode == nil {
  1161. // err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1162. // fmt.Println("err", err)
  1163. // }
  1164. // }
  1165. // }
  1166. // c.ServeSuccessJSON(map[string]interface{}{
  1167. // "msg": "1",
  1168. // "advice": advice,
  1169. // "ids": ids,
  1170. // })
  1171. // return
  1172. // }
  1173. //}
  1174. //自备药
  1175. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  1176. if selfPrescriptionOutOpen.IsOpen == 1 {
  1177. db := service.XTWriteDB()
  1178. tx := db.Begin()
  1179. defer func() {
  1180. if r := recover(); r != nil {
  1181. tx.Rollback()
  1182. } else {
  1183. tx.Commit()
  1184. }
  1185. }()
  1186. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  1187. if selfBasedrug.IsSelfDrug == 1 {
  1188. //查询是否有库存
  1189. infoList, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
  1190. var total_count int64
  1191. var prescribing_number_total int64
  1192. for _, items := range infoList {
  1193. if items.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  1194. items.StockMaxNumber = items.StockMaxNumber * selfBasedrug.MinNumber
  1195. }
  1196. total_count += items.StockMaxNumber + items.StockMinNumber
  1197. }
  1198. if total_count == 0 {
  1199. c.ServeSuccessJSON(map[string]interface{}{
  1200. "msg": "2",
  1201. "advice": advice,
  1202. "ids": ids,
  1203. })
  1204. return
  1205. }
  1206. //判断单位是否相等
  1207. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  1208. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1209. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1210. //转化为最小单位
  1211. prescribing_number_total = count * selfBasedrug.MinNumber
  1212. }
  1213. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  1214. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1215. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1216. prescribing_number_total = count
  1217. }
  1218. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  1219. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1220. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1221. prescribing_number_total = count
  1222. }
  1223. if prescribing_number_total > total_count {
  1224. c.ServeSuccessJSON(map[string]interface{}{
  1225. "msg": "3",
  1226. "advice": advice,
  1227. })
  1228. return
  1229. }
  1230. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  1231. //出库
  1232. if prescribing_number_total <= total_count {
  1233. timeStr := time.Now().Format("2006-01-02")
  1234. timeArr := strings.Split(timeStr, "-")
  1235. total, _ := service.FindAllSelfDrugWarehouseOut(adminUserInfo.Org.Id, tx)
  1236. total = total + 1
  1237. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1238. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1239. number = number + total
  1240. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1241. operation_time := time.Now().Unix()
  1242. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  1243. //创建一个出库单
  1244. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  1245. WarehouseOutOrderNumber: warehousing_out_order,
  1246. OperationTime: operation_time,
  1247. OrgId: adminUserInfo.Org.Id,
  1248. Creater: creater,
  1249. Ctime: time.Now().Unix(),
  1250. Status: 1,
  1251. WarehouseOutTime: advice.AdviceDate,
  1252. Type: 0,
  1253. PatientId: advice.PatientId,
  1254. IsCheck: 1,
  1255. IsSys: 1,
  1256. }
  1257. //查询今日是否有出库数据
  1258. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, advice.AdviceDate, tx, 1)
  1259. if lastWarehouseOut.ID == 0 {
  1260. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  1261. }
  1262. //查询今日是否有出库数据
  1263. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, advice.AdviceDate, tx, 1)
  1264. //出库
  1265. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  1266. WarehouseOutId: lastWarehouseOutOne.ID,
  1267. WarehouseOutOrderNumber: warehousing_out_order,
  1268. DrugId: advice.DrugId,
  1269. Count: prescribing_number_total,
  1270. Price: 0,
  1271. TotalPrice: 0,
  1272. Status: 1,
  1273. Ctime: advice.AdviceDate,
  1274. Mtime: advice.AdviceDate,
  1275. Remark: "",
  1276. OrgId: advice.UserOrgId,
  1277. Type: 0,
  1278. Manufacturer: selfBasedrug.Manufacturer,
  1279. Dealer: selfBasedrug.Dealer,
  1280. RetailPrice: 0,
  1281. RetailTotalPrice: 0,
  1282. CountUnit: selfBasedrug.MinUnit,
  1283. ExpiryDate: 0,
  1284. ProductDate: 0,
  1285. Number: "",
  1286. BatchNumber: "",
  1287. IsSys: 0,
  1288. WarehouseInfoId: 0,
  1289. AdminUserId: 0,
  1290. StockCount: "",
  1291. IsCheck: 1,
  1292. SysRecordTime: advice.AdviceDate,
  1293. PatientId: advice.PatientId,
  1294. AdviceId: advice.ID,
  1295. ClassType: "",
  1296. }
  1297. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1298. for _, it := range warehousingOutInfo {
  1299. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  1300. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  1301. //出库逻辑
  1302. service.AutoSelfDrugDeliverInfoFourtyTwo(adminUserInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  1303. //查询剩余库存
  1304. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  1305. var sum_count int64
  1306. for _, its := range stockInfo {
  1307. if its.MaxUnit == medical.MaxUnit {
  1308. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1309. }
  1310. sum_count += its.StockMaxNumber + its.StockMinNumber
  1311. }
  1312. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  1313. }
  1314. }
  1315. }
  1316. }
  1317. c.ServeSuccessJSON(map[string]interface{}{
  1318. "msg": "1",
  1319. "advice": advice,
  1320. "ids": ids,
  1321. })
  1322. return
  1323. } else if origin == 2 {
  1324. // 开始主事务
  1325. db := service.XTWriteDB()
  1326. tx := db.Begin()
  1327. // 在函数结束时处理事务回滚
  1328. defer func() {
  1329. if r := recover(); r != nil {
  1330. tx.Rollback()
  1331. }
  1332. }()
  1333. adminInfo := c.GetMobileAdminUserInfo()
  1334. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  1335. var ids []string
  1336. advice_ids := c.GetString("advice_id")
  1337. ids = strings.Split(advice_ids, ",")
  1338. if len(execution_time) <= 0 {
  1339. utils.ErrorLog("execution_time")
  1340. tx.Rollback()
  1341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1342. return
  1343. }
  1344. timeLayout2 := "2006-01-02 15:04:05"
  1345. loc, _ := time.LoadLocation("Local")
  1346. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1347. if errs != nil {
  1348. utils.ErrorLog(errs.Error())
  1349. tx.Rollback()
  1350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1351. return
  1352. }
  1353. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1354. var err error
  1355. for _, item := range advices {
  1356. if item.ExecutionState == 1 {
  1357. tx.Rollback()
  1358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1359. return
  1360. }
  1361. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  1362. tx.Rollback()
  1363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1364. return
  1365. }
  1366. if item.StartTime > theTime.Unix() {
  1367. tx.Rollback()
  1368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1369. return
  1370. }
  1371. item.ExecutionState = 1
  1372. item.ExecutionStaff = adminInfo.AdminUser.Id
  1373. item.ExecutionTime = theTime.Unix()
  1374. item.IsMobile = 1
  1375. // 查询信息规挡的设置天数
  1376. infor, _ := service.GetDialysisInformationSetting(item.UserOrgId)
  1377. if infor.ID > 0 {
  1378. var cha_time int64
  1379. timeNowStr := time.Now().Format("2006-01-02")
  1380. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1381. //今日的日期减去设置的日期
  1382. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1383. if cha_time >= item.AdviceDate {
  1384. //查询审核是否允许
  1385. infor, _ := service.GetDialysisInformationByRecordDate(item.PatientId, item.AdviceDate, item.UserOrgId, 4)
  1386. //申请状态不允许的情况 拒绝修改
  1387. if infor.ApplicationStatus != 1 {
  1388. tx.Rollback()
  1389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1390. return
  1391. }
  1392. }
  1393. }
  1394. service.SaveHisDoctorAdviceOne(item, tx)
  1395. //记录日志
  1396. byterequest, _ := json.Marshal(item)
  1397. adviceLog := models.XtDoctorAdviceLog{
  1398. UserOrgId: item.UserOrgId,
  1399. PatientId: item.PatientId,
  1400. AdminUserId: item.ExecutionStaff,
  1401. Module: 2,
  1402. ErrLog: string(byterequest),
  1403. Status: 1,
  1404. Ctime: time.Now().Unix(),
  1405. Mtime: 0,
  1406. Source: "手机端执行his医嘱",
  1407. RecordDate: item.AdviceDate,
  1408. }
  1409. service.CreateDoctorAdviceLog(adviceLog)
  1410. if err == nil {
  1411. drugError := models.XtDrugError{
  1412. UserOrgId: adminInfo.Org.Id,
  1413. DrugId: item.DrugId,
  1414. RecordDate: item.AdviceDate,
  1415. PatientId: item.PatientId,
  1416. Remark: "执行成功",
  1417. Status: 1,
  1418. Ctime: time.Now().Unix(),
  1419. Mtime: 0,
  1420. SumCount: 0,
  1421. Prescribingnumber: item.PrescribingNumber,
  1422. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1423. }
  1424. service.CreateDrugError(drugError)
  1425. }
  1426. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1427. redis := service.RedisClient()
  1428. //清空key 值
  1429. redis.Set(key, "", time.Second)
  1430. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1431. redis.Set(keyTwo, "", time.Second)
  1432. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1433. redis.Set(keyThree, "", time.Second)
  1434. recordDate := theTime.Format("2006-01-02")
  1435. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1436. redis.Set(keyFour, "", time.Second)
  1437. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1438. redis.Set(keyFive, "", time.Second)
  1439. defer redis.Close()
  1440. }
  1441. //药品管理信息
  1442. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  1443. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  1444. if drugStockConfig.IsOpen == 1 {
  1445. for _, item := range advices {
  1446. //查询改药品信息
  1447. medical, _ := service.GetBaseDrugMedicalOne(item.DrugId, tx)
  1448. //判断单位是否合格
  1449. if item.PrescribingNumberUnit != medical.MaxUnit && item.PrescribingNumberUnit != medical.MinUnit {
  1450. //查询该药品是否有出库记录
  1451. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate, tx)
  1452. if len(flowMap) == 0 {
  1453. errs := service.UpdateHisAdviceByIdOne(item.ID, tx)
  1454. if errs != nil {
  1455. drugError := models.XtDrugError{
  1456. UserOrgId: adminInfo.Org.Id,
  1457. DrugId: item.DrugId,
  1458. RecordDate: item.AdviceDate,
  1459. PatientId: item.PatientId,
  1460. Remark: "单位不统一,执行失败",
  1461. Status: 1,
  1462. Ctime: time.Now().Unix(),
  1463. Mtime: 0,
  1464. SumCount: 0,
  1465. Prescribingnumber: item.PrescribingNumber,
  1466. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1467. }
  1468. service.CreateDrugError(drugError)
  1469. }
  1470. }
  1471. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1472. tx.Rollback()
  1473. c.ServeSuccessJSON(map[string]interface{}{
  1474. "msg": "7",
  1475. "advice": advice,
  1476. "ids": ids,
  1477. })
  1478. return
  1479. }
  1480. //查询这个患者这个患者这个药已经出库的所有数量
  1481. advicelist, _ := service.GetAllHisDoctorAdviceByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
  1482. drugoutlist, _ := service.GetAllDrugFlowByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
  1483. var total_count int64
  1484. var drug_count int64
  1485. for _, it := range advicelist {
  1486. if it.PrescribingNumberUnit == medical.MaxUnit {
  1487. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1488. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1489. total_count += prenumber * medical.MinNumber
  1490. }
  1491. if it.PrescribingNumberUnit == medical.MinUnit {
  1492. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1493. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1494. total_count += prenumber
  1495. }
  1496. }
  1497. for _, its := range drugoutlist {
  1498. if its.CountUnit == medical.MaxUnit {
  1499. drug_count += its.Count * medical.MinNumber
  1500. }
  1501. if its.CountUnit == medical.MinUnit {
  1502. drug_count += its.Count
  1503. }
  1504. }
  1505. if total_count == drug_count {
  1506. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1507. tx.Commit()
  1508. c.ServeSuccessJSON(map[string]interface{}{
  1509. "msg": "1",
  1510. "advice": advice,
  1511. "ids": ids,
  1512. })
  1513. return
  1514. }
  1515. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1516. var total int64
  1517. var prescribing_number_total int64
  1518. //保存处方出库
  1519. config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
  1520. if config.IsOpen != 1 {
  1521. //查询该药品是否有库存
  1522. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1523. list, _ := service.GetDrugTotalCountTwoTwety(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut, tx)
  1524. //判断单位是否相等
  1525. if medical.MaxUnit == advice.PrescribingNumberUnit && medical.MaxUnit != medical.MinUnit {
  1526. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1527. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1528. //转化为最小单位
  1529. total = list.Count*medical.MinNumber + list.StockMinNumber
  1530. prescribing_number_total = count * medical.MinNumber
  1531. }
  1532. if medical.MinUnit == advice.PrescribingNumberUnit && medical.MaxUnit != medical.MinUnit {
  1533. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1534. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1535. total = list.Count*medical.MinNumber + list.StockMinNumber
  1536. prescribing_number_total = count
  1537. }
  1538. if medical.MinUnit == advice.PrescribingNumberUnit && medical.MaxUnit == medical.MinUnit {
  1539. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1540. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1541. total = list.Count*medical.MinNumber + list.StockMinNumber
  1542. prescribing_number_total = count
  1543. }
  1544. if medical.IsUse == 1 {
  1545. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1546. drugError := models.XtDrugError{
  1547. UserOrgId: adminInfo.Org.Id,
  1548. DrugId: item.DrugId,
  1549. RecordDate: item.AdviceDate,
  1550. PatientId: item.PatientId,
  1551. Remark: "零用药品库存不足",
  1552. Status: 1,
  1553. Ctime: time.Now().Unix(),
  1554. Mtime: 0,
  1555. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1556. Prescribingnumber: advice.PrescribingNumber,
  1557. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1558. }
  1559. service.CreateDrugError(drugError)
  1560. tx.Rollback()
  1561. c.ServeSuccessJSON(map[string]interface{}{
  1562. "msg": "1",
  1563. "advice": advice,
  1564. "ids": ids,
  1565. })
  1566. return
  1567. }
  1568. }
  1569. if medical.IsUse != 1 {
  1570. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1571. drugError := models.XtDrugError{
  1572. UserOrgId: adminInfo.Org.Id,
  1573. DrugId: item.DrugId,
  1574. RecordDate: item.AdviceDate,
  1575. PatientId: item.PatientId,
  1576. Remark: "药品库存不足",
  1577. Status: 1,
  1578. Ctime: time.Now().Unix(),
  1579. Mtime: 0,
  1580. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1581. Prescribingnumber: advice.PrescribingNumber,
  1582. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1583. }
  1584. service.CreateDrugError(drugError)
  1585. tx.Rollback()
  1586. c.ServeSuccessJSON(map[string]interface{}{
  1587. "msg": "3",
  1588. "advice": advice,
  1589. "ids": ids,
  1590. })
  1591. return
  1592. }
  1593. if prescribing_number_total > total {
  1594. drugError := models.XtDrugError{
  1595. UserOrgId: adminInfo.Org.Id,
  1596. DrugId: item.DrugId,
  1597. RecordDate: item.AdviceDate,
  1598. PatientId: item.PatientId,
  1599. Remark: "出库数量大于库存",
  1600. Status: 1,
  1601. Ctime: time.Now().Unix(),
  1602. Mtime: 0,
  1603. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1604. Prescribingnumber: advice.PrescribingNumber,
  1605. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1606. }
  1607. service.CreateDrugError(drugError)
  1608. tx.Rollback()
  1609. c.ServeSuccessJSON(map[string]interface{}{
  1610. "msg": "2",
  1611. "advice": advice,
  1612. "ids": ids,
  1613. })
  1614. return
  1615. }
  1616. }
  1617. if prescribing_number_total <= total {
  1618. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1619. //判断药品是否零用
  1620. if medical.IsUse == 2 {
  1621. if config.IsOpen != 1 {
  1622. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1623. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1624. //查询该药品是否有出库记录
  1625. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
  1626. if len(flowMap) == 0 {
  1627. errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
  1628. if errs != nil {
  1629. drugError := models.XtDrugError{
  1630. UserOrgId: adminInfo.Org.Id,
  1631. DrugId: item.DrugId,
  1632. RecordDate: item.AdviceDate,
  1633. PatientId: item.PatientId,
  1634. Remark: "出库记录为空,更新执行人失败",
  1635. Status: 1,
  1636. Ctime: time.Now().Unix(),
  1637. Mtime: 0,
  1638. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1639. Prescribingnumber: advice.PrescribingNumber,
  1640. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1641. }
  1642. service.CreateDrugError(drugError)
  1643. }
  1644. tx.Rollback()
  1645. c.ServeSuccessJSON(map[string]interface{}{
  1646. "msg": "6",
  1647. "advice": advice,
  1648. "ids": ids,
  1649. })
  1650. return
  1651. }
  1652. }
  1653. }
  1654. if pharmacyConfig.IsOpen != 1 {
  1655. //查询已经出库数量
  1656. outListExport, _ := service.GetWarehouseOutListExport(advice.DrugId, advice.PatientId, advice.AdviceDate, advice.ID)
  1657. var out_count int64
  1658. if len(outListExport) > 0 {
  1659. for _, item := range outListExport {
  1660. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1661. out_count = item.Count * medical.MinNumber
  1662. }
  1663. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1664. out_count = item.Count
  1665. }
  1666. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  1667. out_count = item.Count * medical.MinNumber
  1668. }
  1669. }
  1670. }
  1671. newadviceInfo := &models.HisDoctorAdviceInfo{
  1672. ID: advice.ID,
  1673. UserOrgId: advice.UserOrgId,
  1674. PatientId: advice.PatientId,
  1675. HisPatientId: advice.HisPatientId,
  1676. AdviceType: advice.AdviceType,
  1677. AdviceDate: advice.AdviceDate,
  1678. StartTime: advice.StartTime,
  1679. AdviceName: advice.AdviceName,
  1680. AdviceDesc: advice.AdviceDesc,
  1681. ReminderDate: advice.ReminderDate,
  1682. SingleDose: advice.SingleDose,
  1683. SingleDoseUnit: advice.SingleDoseUnit,
  1684. PrescribingNumber: advice.PrescribingNumber,
  1685. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1686. DeliveryWay: advice.DeliveryWay,
  1687. ExecutionFrequency: advice.ExecutionFrequency,
  1688. AdviceDoctor: advice.AdviceDoctor,
  1689. Status: advice.Status,
  1690. CreatedTime: advice.CreatedTime,
  1691. UpdatedTime: advice.UpdatedTime,
  1692. AdviceAffirm: advice.AdviceAffirm,
  1693. Remark: advice.Remark,
  1694. StopTime: advice.StopTime,
  1695. StopReason: advice.StopReason,
  1696. StopDoctor: advice.StopDoctor,
  1697. StopState: advice.StopState,
  1698. ParentId: advice.ParentId,
  1699. ExecutionTime: advice.ExecutionTime,
  1700. ExecutionStaff: advice.ExecutionStaff,
  1701. ExecutionState: advice.ExecutionState,
  1702. Checker: advice.Checker,
  1703. RecordDate: advice.RecordDate,
  1704. DialysisOrderId: advice.DialysisOrderId,
  1705. CheckTime: advice.CheckTime,
  1706. CheckState: advice.CheckState,
  1707. DrugSpec: advice.DrugSpec,
  1708. DrugSpecUnit: advice.DrugSpecUnit,
  1709. Groupno: advice.Groupno,
  1710. RemindType: advice.RemindType,
  1711. FrequencyType: advice.FrequencyType,
  1712. DayCount: advice.DayCount,
  1713. WeekDay: advice.WeekDay,
  1714. TemplateId: advice.TemplateId,
  1715. Modifier: advice.Modifier,
  1716. DrugId: advice.DrugId,
  1717. Price: advice.Price,
  1718. PrescriptionId: advice.PrescriptionId,
  1719. MedListCodg: advice.MedListCodg,
  1720. FeedetlSn: advice.FeedetlSn,
  1721. Day: advice.DayCount,
  1722. ChildDoctorAdvice: nil,
  1723. Drug: models.Drug{},
  1724. Diagnosis: advice.Diagnosis,
  1725. Way: advice.Way,
  1726. HospApprFlag: advice.HospApprFlag,
  1727. LmtUsedFlag: advice.LmtUsedFlag,
  1728. HisOrderInfo: models.HisOrderInfo{},
  1729. IsMedicine: advice.IsMedicine,
  1730. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  1731. Child: nil,
  1732. IsSettle: advice.IsSettle,
  1733. IsMobile: advice.IsMobile,
  1734. IsSelfDrug: advice.IsSelfDrug,
  1735. DrugWayCount: advice.DrugWayCount,
  1736. }
  1737. //如果当前医嘱数量大于历史出库数据则需要出库
  1738. if prescribing_number_total > out_count {
  1739. //按最小单位出库
  1740. var cha_count = prescribing_number_total - out_count
  1741. newadviceInfo.PrescribingNumber = float64(cha_count)
  1742. newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  1743. service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  1744. }
  1745. //如果当前医嘱数量小于历史出库数据则需要退库
  1746. if prescribing_number_total < out_count {
  1747. var cha_count = out_count - prescribing_number_total
  1748. drug, _ := service.FindBaseDrugLibRecordSeven(advice.UserOrgId, advice.DrugId)
  1749. service.NewHisDrugCancelInfo(advice.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  1750. service.NewHisDrugAutoCancelInfo(advice.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  1751. }
  1752. if prescribing_number_total == out_count {
  1753. if out_count == 0 {
  1754. service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  1755. }
  1756. }
  1757. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1758. //查询该药品是否有出库记录
  1759. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
  1760. if len(flowMap) == 0 {
  1761. errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
  1762. if errs != nil {
  1763. drugError := models.XtDrugError{
  1764. UserOrgId: adminInfo.Org.Id,
  1765. DrugId: item.DrugId,
  1766. RecordDate: item.AdviceDate,
  1767. PatientId: item.PatientId,
  1768. Remark: "出库记录为空,更新执行人失败",
  1769. Status: 1,
  1770. Ctime: time.Now().Unix(),
  1771. Mtime: 0,
  1772. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1773. Prescribingnumber: advice.PrescribingNumber,
  1774. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1775. }
  1776. service.CreateDrugError(drugError)
  1777. }
  1778. tx.Rollback()
  1779. c.ServeSuccessJSON(map[string]interface{}{
  1780. "msg": "6",
  1781. "advice": advice,
  1782. "ids": ids,
  1783. })
  1784. return
  1785. }
  1786. }
  1787. }
  1788. //更新字典里面的库存
  1789. stockInfo, _ := service.GetNewDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  1790. var sum_count int64
  1791. for _, its := range stockInfo {
  1792. if its.MaxUnit == medical.MaxUnit {
  1793. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1794. }
  1795. sum_count += its.StockMaxNumber + its.StockMinNumber
  1796. }
  1797. service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  1798. //剩余库存
  1799. service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count, tx)
  1800. }
  1801. }
  1802. }
  1803. }
  1804. //自备药
  1805. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminInfo.Org.Id)
  1806. if selfPrescriptionOutOpen.IsOpen == 1 {
  1807. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  1808. if selfBasedrug.IsSelfDrug == 1 {
  1809. //查询是否有库存
  1810. info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
  1811. if len(info) > 0 {
  1812. var total_count int64
  1813. var prescribing_number_total int64
  1814. for _, item := range info {
  1815. if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  1816. item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
  1817. }
  1818. total_count += item.StockMaxNumber + item.StockMinNumber
  1819. }
  1820. //判断单位是否相等
  1821. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  1822. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1823. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1824. //转化为最小单位
  1825. prescribing_number_total = count * selfBasedrug.MinNumber
  1826. }
  1827. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  1828. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1829. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1830. prescribing_number_total = count
  1831. }
  1832. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  1833. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1834. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1835. prescribing_number_total = count
  1836. }
  1837. if prescribing_number_total > total_count {
  1838. c.ServeSuccessJSON(map[string]interface{}{
  1839. "msg": "3",
  1840. "advice": advice,
  1841. })
  1842. return
  1843. }
  1844. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  1845. //出库
  1846. if prescribing_number_total <= total_count {
  1847. timeStr := time.Now().Format("2006-01-02")
  1848. timeArr := strings.Split(timeStr, "-")
  1849. total, _ := service.FindAllSelfDrugWarehouseOut(adminInfo.Org.Id, tx)
  1850. total = total + 1
  1851. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1852. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1853. number = number + total
  1854. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  1855. operation_time := time.Now().Unix()
  1856. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  1857. //创建一个出库单
  1858. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  1859. WarehouseOutOrderNumber: warehousing_out_order,
  1860. OperationTime: operation_time,
  1861. OrgId: adminInfo.Org.Id,
  1862. Creater: creater,
  1863. Ctime: time.Now().Unix(),
  1864. Status: 1,
  1865. WarehouseOutTime: advice.AdviceDate,
  1866. Type: 0,
  1867. PatientId: advice.PatientId,
  1868. IsCheck: 1,
  1869. IsSys: 1,
  1870. }
  1871. //查询今日是否有出库数据
  1872. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminInfo.Org.Id, advice.AdviceDate, tx, 1)
  1873. if lastWarehouseOut.ID == 0 {
  1874. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  1875. }
  1876. //查询今日是否有出库数据
  1877. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(adminInfo.Org.Id, advice.AdviceDate, tx, 1)
  1878. //出库
  1879. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  1880. WarehouseOutId: lastWarehouseOutOne.ID,
  1881. WarehouseOutOrderNumber: warehousing_out_order,
  1882. DrugId: advice.DrugId,
  1883. Count: prescribing_number_total,
  1884. Price: 0,
  1885. TotalPrice: 0,
  1886. Status: 1,
  1887. Ctime: advice.AdviceDate,
  1888. Mtime: advice.AdviceDate,
  1889. Remark: "",
  1890. OrgId: advice.UserOrgId,
  1891. Type: 0,
  1892. Manufacturer: selfBasedrug.Manufacturer,
  1893. Dealer: selfBasedrug.Dealer,
  1894. RetailPrice: 0,
  1895. RetailTotalPrice: 0,
  1896. CountUnit: selfBasedrug.MinUnit,
  1897. ExpiryDate: 0,
  1898. ProductDate: 0,
  1899. Number: "",
  1900. BatchNumber: "",
  1901. IsSys: 0,
  1902. WarehouseInfoId: 0,
  1903. AdminUserId: 0,
  1904. StockCount: "",
  1905. IsCheck: 1,
  1906. SysRecordTime: advice.AdviceDate,
  1907. PatientId: advice.PatientId,
  1908. AdviceId: advice.ID,
  1909. ClassType: "",
  1910. }
  1911. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  1912. for _, it := range warehousingOutInfo {
  1913. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  1914. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  1915. //出库逻辑
  1916. service.AutoSelfDrugDeliverInfoFourtyTwo(adminInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  1917. //查询剩余库存
  1918. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  1919. var sum_count int64
  1920. for _, its := range stockInfo {
  1921. if its.MaxUnit == medical.MaxUnit {
  1922. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1923. }
  1924. sum_count += its.StockMaxNumber + its.StockMinNumber
  1925. }
  1926. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  1927. }
  1928. }
  1929. } else {
  1930. c.ServeSuccessJSON(map[string]interface{}{
  1931. "msg": "3",
  1932. "advice": advice,
  1933. })
  1934. return
  1935. }
  1936. }
  1937. }
  1938. ////针对异常未出库问题的脚本
  1939. //if adminInfo.Org.Id == 10598 {
  1940. //
  1941. // newadviceInfo := &models.HisDoctorAdviceInfo{
  1942. // ID: advice.ID,
  1943. // UserOrgId: advice.UserOrgId,
  1944. // PatientId: advice.PatientId,
  1945. // HisPatientId: advice.HisPatientId,
  1946. // AdviceType: advice.AdviceType,
  1947. // AdviceDate: advice.AdviceDate,
  1948. // StartTime: advice.StartTime,
  1949. // AdviceName: advice.AdviceName,
  1950. // AdviceDesc: advice.AdviceDesc,
  1951. // ReminderDate: advice.ReminderDate,
  1952. // SingleDose: advice.SingleDose,
  1953. // SingleDoseUnit: advice.SingleDoseUnit,
  1954. // PrescribingNumber: advice.PrescribingNumber,
  1955. // PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1956. // DeliveryWay: advice.DeliveryWay,
  1957. // ExecutionFrequency: advice.ExecutionFrequency,
  1958. // AdviceDoctor: advice.AdviceDoctor,
  1959. // Status: advice.Status,
  1960. // CreatedTime: advice.CreatedTime,
  1961. // UpdatedTime: advice.UpdatedTime,
  1962. // AdviceAffirm: advice.AdviceAffirm,
  1963. // Remark: advice.Remark,
  1964. // StopTime: advice.StopTime,
  1965. // StopReason: advice.StopReason,
  1966. // StopDoctor: advice.StopDoctor,
  1967. // StopState: advice.StopState,
  1968. // ParentId: advice.ParentId,
  1969. // ExecutionTime: advice.ExecutionTime,
  1970. // ExecutionStaff: advice.ExecutionStaff,
  1971. // ExecutionState: advice.ExecutionState,
  1972. // Checker: advice.Checker,
  1973. // RecordDate: advice.RecordDate,
  1974. // DialysisOrderId: advice.DialysisOrderId,
  1975. // CheckTime: advice.CheckTime,
  1976. // CheckState: advice.CheckState,
  1977. // DrugSpec: advice.DrugSpec,
  1978. // DrugSpecUnit: advice.DrugSpecUnit,
  1979. // Groupno: advice.Groupno,
  1980. // RemindType: advice.RemindType,
  1981. // FrequencyType: advice.FrequencyType,
  1982. // DayCount: advice.DayCount,
  1983. // WeekDay: advice.WeekDay,
  1984. // TemplateId: advice.TemplateId,
  1985. // Modifier: advice.Modifier,
  1986. // DrugId: advice.DrugId,
  1987. // Price: advice.Price,
  1988. // PrescriptionId: advice.PrescriptionId,
  1989. // MedListCodg: advice.MedListCodg,
  1990. // FeedetlSn: advice.FeedetlSn,
  1991. // Day: advice.DayCount,
  1992. // ChildDoctorAdvice: nil,
  1993. // Drug: models.Drug{},
  1994. // Diagnosis: advice.Diagnosis,
  1995. // Way: advice.Way,
  1996. // HospApprFlag: advice.HospApprFlag,
  1997. // LmtUsedFlag: advice.LmtUsedFlag,
  1998. // HisOrderInfo: models.HisOrderInfo{},
  1999. // IsMedicine: advice.IsMedicine,
  2000. // ExecutionFrequencyId: advice.ExecutionFrequencyId,
  2001. // Child: nil,
  2002. // IsSettle: advice.IsSettle,
  2003. // IsMobile: advice.IsMobile,
  2004. // IsSelfDrug: advice.IsSelfDrug,
  2005. // DrugWayCount: advice.DrugWayCount,
  2006. // }
  2007. // outListExport, _ := service.GetWarehouseOutListExport(advice.DrugId, advice.PatientId, advice.AdviceDate, advice.ID)
  2008. //
  2009. // var out_count int64
  2010. // if len(outListExport) > 0 {
  2011. // for _, item := range outListExport {
  2012. // if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2013. // out_count = item.Count * medical.MinNumber
  2014. // }
  2015. // if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2016. // out_count = item.Count
  2017. // }
  2018. // if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2019. // out_count = item.Count * medical.MinNumber
  2020. // }
  2021. //
  2022. // }
  2023. // }
  2024. // //按最小单位出库
  2025. // //var cha_count = total_count - out_count
  2026. // fmt.Println("cha_count--------------------------------------", out_count)
  2027. //
  2028. // var cha_count = 1
  2029. // newadviceInfo.PrescribingNumber = float64(cha_count)
  2030. // newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  2031. // service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  2032. //}
  2033. }
  2034. }
  2035. tx.Commit()
  2036. for _, item := range advices {
  2037. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  2038. c.ServeSuccessJSON(map[string]interface{}{
  2039. "msg": "1",
  2040. "advice": advice,
  2041. "ids": ids,
  2042. })
  2043. }
  2044. }
  2045. }
  2046. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  2047. execution_time := c.GetString("execution_time")
  2048. fmt.Println("execution_time", execution_time)
  2049. groupno, _ := c.GetInt64("groupno", -1)
  2050. //patient_id, _ := c.GetInt64("patient_id")
  2051. advice_date, _ := c.GetInt64("advice_date")
  2052. var ids []string
  2053. if groupno == 0 {
  2054. advice_ids := c.GetString("advice_id")
  2055. ids = strings.Split(advice_ids, ",")
  2056. }
  2057. if groupno < 0 {
  2058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2059. return
  2060. }
  2061. if len(execution_time) <= 0 {
  2062. utils.ErrorLog("execution_time")
  2063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2064. return
  2065. }
  2066. timeLayout2 := "2006-01-02 15:04:05"
  2067. loc, _ := time.LoadLocation("Local")
  2068. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2069. if errs != nil {
  2070. utils.ErrorLog(errs.Error())
  2071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2072. return
  2073. }
  2074. adminUserInfo := c.GetMobileAdminUserInfo()
  2075. var advice models.DoctorAdvice
  2076. if groupno > 0 {
  2077. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2078. for _, item := range advices {
  2079. if item.ExecutionState == 1 {
  2080. advice = item
  2081. }
  2082. }
  2083. } else {
  2084. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2085. for _, item := range advices {
  2086. if item.ExecutionState == 1 {
  2087. advice = item
  2088. }
  2089. }
  2090. }
  2091. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  2092. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2093. // if getPermissionErr != nil {
  2094. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2095. // return
  2096. // } else if headNursePermission == nil {
  2097. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2098. // return
  2099. // }
  2100. //}
  2101. if advice.StartTime > theTime.Unix() {
  2102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2103. return
  2104. }
  2105. advices := models.DoctorAdvice{
  2106. ExecutionTime: theTime.Unix(),
  2107. UpdatedTime: time.Now().Unix(),
  2108. }
  2109. var err error
  2110. if groupno > 0 {
  2111. // 查询信息规挡的设置天数
  2112. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2113. if infor.ID > 0 {
  2114. var cha_time int64
  2115. timeNowStr := time.Now().Format("2006-01-02")
  2116. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2117. //今日的日期减去设置的日期
  2118. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2119. if cha_time >= advices.AdviceDate {
  2120. //查询审核是否允许
  2121. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2122. //申请状态不允许的情况 拒绝修改
  2123. if infor.ApplicationStatus != 1 {
  2124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2125. return
  2126. }
  2127. }
  2128. }
  2129. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  2130. //记录日志
  2131. byterequest, _ := json.Marshal(advices)
  2132. adviceLog := models.XtDoctorAdviceLog{
  2133. UserOrgId: adminUserInfo.Org.Id,
  2134. PatientId: advices.PatientId,
  2135. AdminUserId: adminUserInfo.AdminUser.Id,
  2136. Module: 1,
  2137. ErrLog: string(byterequest),
  2138. Status: 1,
  2139. Ctime: time.Now().Unix(),
  2140. Mtime: 0,
  2141. Source: "手机端编辑医嘱",
  2142. RecordDate: advices.AdviceDate,
  2143. }
  2144. service.CreateDoctorAdviceLog(adviceLog)
  2145. redis := service.RedisClient()
  2146. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2147. redis.Set(key, "", time.Second)
  2148. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2149. redis.Set(keyOne, "", time.Second)
  2150. defer redis.Close()
  2151. } else {
  2152. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2153. if infor.ID > 0 {
  2154. var cha_time int64
  2155. timeNowStr := time.Now().Format("2006-01-02")
  2156. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2157. //今日的日期减去设置的日期
  2158. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2159. if cha_time >= advices.AdviceDate {
  2160. //查询审核是否允许
  2161. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2162. //申请状态不允许的情况 拒绝修改
  2163. if infor.ApplicationStatus != 1 {
  2164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2165. return
  2166. }
  2167. }
  2168. }
  2169. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  2170. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  2171. //记录日志
  2172. byterequest, _ := json.Marshal(advices)
  2173. adviceLog := models.XtDoctorAdviceLog{
  2174. UserOrgId: adminUserInfo.Org.Id,
  2175. PatientId: advices.PatientId,
  2176. AdminUserId: adminUserInfo.AdminUser.Id,
  2177. Module: 1,
  2178. ErrLog: string(byterequest),
  2179. Status: 1,
  2180. Ctime: time.Now().Unix(),
  2181. Mtime: 0,
  2182. Source: "手机端编辑执行医嘱",
  2183. RecordDate: advices.AdviceDate,
  2184. }
  2185. service.CreateDoctorAdviceLog(adviceLog)
  2186. redis := service.RedisClient()
  2187. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2188. redis.Set(key, "", time.Second)
  2189. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  2190. redis.Set(keyOne, "", time.Second)
  2191. defer redis.Close()
  2192. }
  2193. //判断是否开启his
  2194. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  2195. //如果开启去修改执行时间
  2196. if config.IsOpen == 1 {
  2197. advicesinfo := models.HisDoctorAdviceInfo{
  2198. ExecutionTime: theTime.Unix(),
  2199. UpdatedTime: time.Now().Unix(),
  2200. }
  2201. var advicehis models.HisDoctorAdviceInfo
  2202. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  2203. //记录日志
  2204. byterequest, _ := json.Marshal(advicesinfo)
  2205. adviceLog := models.XtDoctorAdviceLog{
  2206. UserOrgId: adminUserInfo.Org.Id,
  2207. PatientId: advices.PatientId,
  2208. AdminUserId: adminUserInfo.AdminUser.Id,
  2209. Module: 1,
  2210. ErrLog: string(byterequest),
  2211. Status: 1,
  2212. Ctime: time.Now().Unix(),
  2213. Mtime: 0,
  2214. Source: "手机端his编辑医嘱",
  2215. RecordDate: advices.AdviceDate,
  2216. }
  2217. service.CreateDoctorAdviceLog(adviceLog)
  2218. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  2219. for _, item := range his_advices {
  2220. if item.ExecutionState == 1 {
  2221. advicehis = item
  2222. }
  2223. }
  2224. redis := service.RedisClient()
  2225. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  2226. redis.Set(keyThree, "", time.Second)
  2227. recordDate := theTime.Format("2006-01-02")
  2228. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2229. redis.Set(keyFour, "", time.Second)
  2230. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  2231. redis.Set(keyFive, "", time.Second)
  2232. defer redis.Close()
  2233. project := models.HisPrescriptionProject{
  2234. ExecutionTime: theTime.Unix(),
  2235. Mtime: time.Now().Unix(),
  2236. }
  2237. service.ModifyHisPrescriptionProject(&project, ids)
  2238. //记录日志
  2239. projectquerst, _ := json.Marshal(project)
  2240. projectLog := models.XtDoctorAdviceLog{
  2241. UserOrgId: adminUserInfo.Org.Id,
  2242. PatientId: advices.PatientId,
  2243. AdminUserId: adminUserInfo.AdminUser.Id,
  2244. Module: 1,
  2245. ErrLog: string(projectquerst),
  2246. Status: 1,
  2247. Ctime: time.Now().Unix(),
  2248. Mtime: 0,
  2249. Source: "手机端his编辑项目医嘱",
  2250. RecordDate: advices.AdviceDate,
  2251. }
  2252. service.CreateDoctorAdviceLog(projectLog)
  2253. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  2254. redis.Set(keyEnd, "", time.Second)
  2255. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2256. redis.Set(keyFours, "", time.Second)
  2257. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  2258. redis.Set(keyFives, "", time.Second)
  2259. defer redis.Close()
  2260. }
  2261. if err != nil {
  2262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2263. return
  2264. }
  2265. advice.ExecutionTime = theTime.Unix()
  2266. c.ServeSuccessJSON(map[string]interface{}{
  2267. "msg": "ok",
  2268. "advice": advice,
  2269. "ids": ids,
  2270. })
  2271. return
  2272. }
  2273. func (c *PatientApiController) CheckMobileDoctorAdvice() {
  2274. origin, _ := c.GetInt64("origin", 0)
  2275. record_date, _ := c.GetInt64("record_date")
  2276. patient_id, _ := c.GetInt64("patient_id")
  2277. check_time := c.GetString("check_time")
  2278. if len(check_time) <= 0 {
  2279. utils.ErrorLog("check_time")
  2280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2281. return
  2282. }
  2283. timeLayout2 := "2006-01-02 15:04:05"
  2284. loc, _ := time.LoadLocation("Local")
  2285. theTime, errs := time.ParseInLocation(timeLayout2, check_time, loc)
  2286. fmt.Println("theTimewowowow", theTime)
  2287. if errs != nil {
  2288. utils.ErrorLog(errs.Error())
  2289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2290. return
  2291. }
  2292. if origin != 2 {
  2293. groupno, _ := c.GetInt64("groupno", -1)
  2294. var ids []string
  2295. if groupno == 0 {
  2296. advice_ids := c.GetString("advice_id")
  2297. if advice_ids == "" {
  2298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2299. return
  2300. } else {
  2301. ids = strings.Split(advice_ids, ",")
  2302. if len(ids) <= 0 {
  2303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2304. return
  2305. }
  2306. }
  2307. }
  2308. if groupno < 0 {
  2309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2310. return
  2311. }
  2312. adminUserInfo := c.GetMobileAdminUserInfo()
  2313. var advice models.DoctorAdvice
  2314. if groupno > 0 {
  2315. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2316. for _, item := range advices {
  2317. if item.CheckState == 0 {
  2318. advice = item
  2319. }
  2320. //记录日志
  2321. byterequest, _ := json.Marshal(advices)
  2322. adviceLog := models.XtDoctorAdviceLog{
  2323. UserOrgId: adminUserInfo.Org.Id,
  2324. PatientId: item.PatientId,
  2325. AdminUserId: adminUserInfo.AdminUser.Id,
  2326. Module: 3,
  2327. ErrLog: string(byterequest),
  2328. Status: 1,
  2329. Ctime: time.Now().Unix(),
  2330. Mtime: 0,
  2331. Source: "手机端核对医嘱",
  2332. RecordDate: item.AdviceDate,
  2333. }
  2334. service.CreateDoctorAdviceLog(adviceLog)
  2335. }
  2336. if advice.CheckState == 1 {
  2337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2338. return
  2339. }
  2340. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2342. return
  2343. }
  2344. } else {
  2345. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2346. for _, item := range advices {
  2347. if item.CheckState == 0 {
  2348. advice = item
  2349. }
  2350. //记录日志
  2351. byterequest, _ := json.Marshal(advices)
  2352. adviceLog := models.XtDoctorAdviceLog{
  2353. UserOrgId: adminUserInfo.Org.Id,
  2354. PatientId: item.PatientId,
  2355. AdminUserId: adminUserInfo.AdminUser.Id,
  2356. Module: 3,
  2357. ErrLog: string(byterequest),
  2358. Status: 1,
  2359. Ctime: time.Now().Unix(),
  2360. Mtime: 0,
  2361. Source: "手机端核对医嘱",
  2362. RecordDate: item.AdviceDate,
  2363. }
  2364. service.CreateDoctorAdviceLog(adviceLog)
  2365. }
  2366. if advice.CheckState == 1 {
  2367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2368. return
  2369. }
  2370. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2372. return
  2373. }
  2374. }
  2375. checker := adminUserInfo.AdminUser.Id
  2376. advices := models.DoctorAdvice{
  2377. CheckTime: theTime.Unix(),
  2378. Checker: checker,
  2379. UpdatedTime: time.Now().Unix(),
  2380. }
  2381. fmt.Println("groupnowowowowoowowow", groupno)
  2382. var err error
  2383. if groupno > 0 {
  2384. // 查询信息规挡的设置天数
  2385. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2386. if infor.ID > 0 && infor.WeekDay > 0 {
  2387. var cha_time int64
  2388. timeNowStr := time.Now().Format("2006-01-02")
  2389. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2390. //今日的日期减去设置的日期
  2391. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2392. if cha_time >= record_date {
  2393. //查询审核是否允许
  2394. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2395. //申请状态不允许的情况 拒绝修改
  2396. if infor.ApplicationStatus != 1 {
  2397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2398. return
  2399. }
  2400. }
  2401. }
  2402. err = service.CheckDoctorAdviceByGroupNoOne(&advices, groupno, adminUserInfo.Org.Id)
  2403. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2404. redis := service.RedisClient()
  2405. //清空key 值
  2406. redis.Set(key, "", time.Second)
  2407. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2408. redis.Set(keyTwo, "", time.Second)
  2409. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2410. redis.Set(keyThree, "", time.Second)
  2411. recordDate := theTime.Format("2006-01-02")
  2412. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2413. redis.Set(keyFour, "", time.Second)
  2414. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2415. redis.Set(keyFive, "", time.Second)
  2416. defer redis.Close()
  2417. } else {
  2418. if len(ids[0]) <= 0 {
  2419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2420. return
  2421. } else {
  2422. //t := time.Now().Format("2006-01-02")/**/
  2423. //timeLayout2 := "2006-01-02"
  2424. //loc, _ := time.LoadLocation("Local")
  2425. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2426. // 查询信息规挡的设置天数
  2427. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2428. if infor.ID > 0 {
  2429. var cha_time int64
  2430. timeNowStr := time.Now().Format("2006-01-02")
  2431. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2432. //今日的日期减去设置的日期
  2433. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2434. if cha_time >= advices.AdviceDate {
  2435. //查询审核是否允许
  2436. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2437. //申请状态不允许的情况 拒绝修改
  2438. if infor.ApplicationStatus != 1 {
  2439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2440. return
  2441. }
  2442. }
  2443. }
  2444. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2445. //记录日志
  2446. byterequest, _ := json.Marshal(advices)
  2447. adviceLog := models.XtDoctorAdviceLog{
  2448. UserOrgId: adminUserInfo.Org.Id,
  2449. PatientId: advices.PatientId,
  2450. AdminUserId: advices.Checker,
  2451. Module: 3,
  2452. ErrLog: string(byterequest),
  2453. Status: 1,
  2454. Ctime: time.Now().Unix(),
  2455. Mtime: 0,
  2456. Source: "手机端核对医嘱",
  2457. RecordDate: advices.AdviceDate,
  2458. }
  2459. service.CreateDoctorAdviceLog(adviceLog)
  2460. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2461. redis := service.RedisClient()
  2462. //清空key 值
  2463. redis.Set(key, "", time.Second)
  2464. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2465. redis.Set(keyTwo, "", time.Second)
  2466. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2467. redis.Set(keyThree, "", time.Second)
  2468. recordDate := theTime.Format("2006-01-02")
  2469. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2470. redis.Set(keyFour, "", time.Second)
  2471. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2472. redis.Set(keyFive, "", time.Second)
  2473. defer redis.Close()
  2474. }
  2475. }
  2476. if err != nil {
  2477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2478. return
  2479. }
  2480. advice.Checker = checker
  2481. advice.CheckTime = theTime.Unix()
  2482. advice.CheckState = 1
  2483. c.ServeSuccessJSON(map[string]interface{}{
  2484. "msg": "ok",
  2485. "advice": advice,
  2486. })
  2487. }
  2488. return
  2489. }
  2490. func (c *PatientApiController) CheckDoctorAdvice() {
  2491. origin, _ := c.GetInt64("origin", 0)
  2492. record_date, _ := c.GetInt64("record_date")
  2493. patient_id, _ := c.GetInt64("patient_id")
  2494. if origin != 2 {
  2495. groupno, _ := c.GetInt64("groupno", -1)
  2496. var ids []string
  2497. if groupno == 0 {
  2498. advice_ids := c.GetString("advice_id")
  2499. if advice_ids == "" {
  2500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2501. return
  2502. } else {
  2503. ids = strings.Split(advice_ids, ",")
  2504. if len(ids) <= 0 {
  2505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2506. return
  2507. }
  2508. }
  2509. }
  2510. if groupno < 0 {
  2511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2512. return
  2513. }
  2514. adminUserInfo := c.GetMobileAdminUserInfo()
  2515. var advice models.DoctorAdvice
  2516. if groupno > 0 {
  2517. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2518. for _, item := range advices {
  2519. if item.CheckState == 0 {
  2520. advice = item
  2521. }
  2522. //记录日志
  2523. byterequest, _ := json.Marshal(advices)
  2524. adviceLog := models.XtDoctorAdviceLog{
  2525. UserOrgId: adminUserInfo.Org.Id,
  2526. PatientId: item.PatientId,
  2527. AdminUserId: adminUserInfo.AdminUser.Id,
  2528. Module: 3,
  2529. ErrLog: string(byterequest),
  2530. Status: 1,
  2531. Ctime: time.Now().Unix(),
  2532. Mtime: 0,
  2533. Source: "手机端核对医嘱",
  2534. RecordDate: item.AdviceDate,
  2535. }
  2536. service.CreateDoctorAdviceLog(adviceLog)
  2537. }
  2538. if advice.CheckState == 1 {
  2539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2540. return
  2541. }
  2542. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2544. return
  2545. }
  2546. } else {
  2547. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2548. for _, item := range advices {
  2549. if item.CheckState == 0 {
  2550. advice = item
  2551. }
  2552. //记录日志
  2553. byterequest, _ := json.Marshal(advices)
  2554. adviceLog := models.XtDoctorAdviceLog{
  2555. UserOrgId: adminUserInfo.Org.Id,
  2556. PatientId: item.PatientId,
  2557. AdminUserId: adminUserInfo.AdminUser.Id,
  2558. Module: 3,
  2559. ErrLog: string(byterequest),
  2560. Status: 1,
  2561. Ctime: time.Now().Unix(),
  2562. Mtime: 0,
  2563. Source: "手机端核对医嘱",
  2564. RecordDate: item.AdviceDate,
  2565. }
  2566. service.CreateDoctorAdviceLog(adviceLog)
  2567. }
  2568. if advice.CheckState == 1 {
  2569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2570. return
  2571. }
  2572. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2574. return
  2575. }
  2576. }
  2577. checker := adminUserInfo.AdminUser.Id
  2578. theTime := time.Now()
  2579. advices := models.DoctorAdvice{
  2580. CheckTime: theTime.Unix(),
  2581. Checker: checker,
  2582. UpdatedTime: time.Now().Unix(),
  2583. }
  2584. var err error
  2585. if groupno > 0 {
  2586. // 查询信息规挡的设置天数
  2587. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2588. if infor.ID > 0 && infor.WeekDay > 0 {
  2589. var cha_time int64
  2590. timeNowStr := time.Now().Format("2006-01-02")
  2591. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2592. //今日的日期减去设置的日期
  2593. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2594. if cha_time >= record_date {
  2595. //查询审核是否允许
  2596. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2597. //申请状态不允许的情况 拒绝修改
  2598. if infor.ApplicationStatus != 1 {
  2599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2600. return
  2601. }
  2602. }
  2603. }
  2604. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  2605. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2606. redis := service.RedisClient()
  2607. //清空key 值
  2608. redis.Set(key, "", time.Second)
  2609. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2610. redis.Set(keyTwo, "", time.Second)
  2611. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2612. redis.Set(keyThree, "", time.Second)
  2613. recordDate := theTime.Format("2006-01-02")
  2614. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2615. redis.Set(keyFour, "", time.Second)
  2616. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2617. redis.Set(keyFive, "", time.Second)
  2618. defer redis.Close()
  2619. } else {
  2620. if len(ids[0]) <= 0 {
  2621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2622. return
  2623. } else {
  2624. //t := time.Now().Format("2006-01-02")/**/
  2625. //timeLayout2 := "2006-01-02"
  2626. //loc, _ := time.LoadLocation("Local")
  2627. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2628. // 查询信息规挡的设置天数
  2629. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2630. if infor.ID > 0 {
  2631. var cha_time int64
  2632. timeNowStr := time.Now().Format("2006-01-02")
  2633. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2634. //今日的日期减去设置的日期
  2635. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2636. if cha_time >= advices.AdviceDate {
  2637. //查询审核是否允许
  2638. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2639. //申请状态不允许的情况 拒绝修改
  2640. if infor.ApplicationStatus != 1 {
  2641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2642. return
  2643. }
  2644. }
  2645. }
  2646. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2647. //记录日志
  2648. byterequest, _ := json.Marshal(advices)
  2649. adviceLog := models.XtDoctorAdviceLog{
  2650. UserOrgId: adminUserInfo.Org.Id,
  2651. PatientId: advices.PatientId,
  2652. AdminUserId: advices.Checker,
  2653. Module: 3,
  2654. ErrLog: string(byterequest),
  2655. Status: 1,
  2656. Ctime: time.Now().Unix(),
  2657. Mtime: 0,
  2658. Source: "手机端核对医嘱",
  2659. RecordDate: advices.AdviceDate,
  2660. }
  2661. service.CreateDoctorAdviceLog(adviceLog)
  2662. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2663. redis := service.RedisClient()
  2664. //清空key 值
  2665. redis.Set(key, "", time.Second)
  2666. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2667. redis.Set(keyTwo, "", time.Second)
  2668. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2669. redis.Set(keyThree, "", time.Second)
  2670. recordDate := theTime.Format("2006-01-02")
  2671. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2672. redis.Set(keyFour, "", time.Second)
  2673. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2674. redis.Set(keyFive, "", time.Second)
  2675. defer redis.Close()
  2676. }
  2677. }
  2678. if err != nil {
  2679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2680. return
  2681. }
  2682. advice.Checker = checker
  2683. advice.CheckTime = theTime.Unix()
  2684. advice.CheckState = 1
  2685. c.ServeSuccessJSON(map[string]interface{}{
  2686. "msg": "ok",
  2687. "advice": advice,
  2688. })
  2689. } else if origin == 2 {
  2690. adminInfo := c.GetMobileAdminUserInfo()
  2691. var ids []string
  2692. advice_ids := c.GetString("advice_id")
  2693. ids = strings.Split(advice_ids, ",")
  2694. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  2695. var err error
  2696. for _, item := range advices {
  2697. if item.CheckState == 1 {
  2698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2699. return
  2700. }
  2701. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  2702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2703. return
  2704. }
  2705. item.Checker = adminInfo.AdminUser.Id
  2706. item.CheckTime = time.Now().Unix()
  2707. item.CheckState = 1
  2708. // 查询信息规挡的设置天数
  2709. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  2710. if infor.ID > 0 {
  2711. var cha_time int64
  2712. timeNowStr := time.Now().Format("2006-01-02")
  2713. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2714. //今日的日期减去设置的日期
  2715. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2716. if cha_time >= record_date {
  2717. //查询审核是否允许
  2718. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminInfo.Org.Id, 4)
  2719. //申请状态不允许的情况 拒绝修改
  2720. if infor.ApplicationStatus != 1 {
  2721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2722. return
  2723. }
  2724. }
  2725. }
  2726. err = service.SaveHisDoctorAdvice(item)
  2727. //记录日志
  2728. byterequest, _ := json.Marshal(advices)
  2729. adviceLog := models.XtDoctorAdviceLog{
  2730. UserOrgId: adminInfo.Org.Id,
  2731. PatientId: item.PatientId,
  2732. AdminUserId: item.Checker,
  2733. Module: 3,
  2734. ErrLog: string(byterequest),
  2735. Status: 1,
  2736. Ctime: time.Now().Unix(),
  2737. Mtime: 0,
  2738. Source: "手机端核对His医嘱",
  2739. RecordDate: item.AdviceDate,
  2740. }
  2741. service.CreateDoctorAdviceLog(adviceLog)
  2742. redis := service.RedisClient()
  2743. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2744. //清空key 值
  2745. redis.Set(key, "", time.Second)
  2746. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2747. redis.Set(keyTwo, "", time.Second)
  2748. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2749. redis.Set(keyThree, "", time.Second)
  2750. theTime := time.Now()
  2751. recordDate := theTime.Format("2006-01-02")
  2752. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  2753. redis.Set(keyFour, "", time.Second)
  2754. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2755. redis.Set(keyFive, "", time.Second)
  2756. defer redis.Close()
  2757. }
  2758. if err == nil {
  2759. c.ServeSuccessJSON(map[string]interface{}{
  2760. "msg": "ok",
  2761. "advice": advices,
  2762. })
  2763. } else {
  2764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2765. return
  2766. }
  2767. }
  2768. return
  2769. }
  2770. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  2771. id, _ := c.GetInt64("patient", 0)
  2772. assessmentDate := c.GetString("assessment_date", "")
  2773. if id <= 0 || len(assessmentDate) != 10 {
  2774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2775. return
  2776. }
  2777. timeLayout := "2006-01-02"
  2778. loc, _ := time.LoadLocation("Local")
  2779. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  2780. if err != nil {
  2781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2782. return
  2783. }
  2784. theAssessmentDateTime := theTime.Unix()
  2785. adminUserInfo := c.GetMobileAdminUserInfo()
  2786. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2787. if patient.ID == 0 {
  2788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2789. return
  2790. }
  2791. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2792. if getPEErr != nil {
  2793. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  2794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2795. return
  2796. }
  2797. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2798. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2799. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2800. var evaluation models.PredialysisEvaluation
  2801. if theEvaluation != nil {
  2802. evaluation = *theEvaluation
  2803. }
  2804. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  2805. if code > 0 {
  2806. c.ServeFailJSONWithSGJErrorCode(code)
  2807. return
  2808. }
  2809. if theEvaluation == nil {
  2810. evaluation.CreatedTime = time.Now().Unix()
  2811. evaluation.Status = 1
  2812. evaluation.AssessmentDate = theAssessmentDateTime
  2813. evaluation.PatientId = id
  2814. evaluation.UserOrgId = adminUserInfo.Org.Id
  2815. if appRole.UserType == 2 || appRole.UserType == 1 {
  2816. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2817. evaluation.AssessmentTime = time.Now().Unix()
  2818. } else {
  2819. evaluation.Creater = adminUserInfo.AdminUser.Id
  2820. }
  2821. } else {
  2822. evaluation.UpdatedTime = time.Now().Unix()
  2823. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  2824. if appRole.UserType == 2 || appRole.UserType == 1 {
  2825. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2826. evaluation.AssessmentTime = time.Now().Unix()
  2827. } else {
  2828. evaluation.Modifier = adminUserInfo.AdminUser.Id
  2829. if evaluation.Creater == 0 {
  2830. evaluation.Creater = adminUserInfo.AdminUser.Id
  2831. }
  2832. }
  2833. }
  2834. //新增逻辑
  2835. var dewater_amount float64
  2836. dewater_amount = 0
  2837. if evaluation.DryWeight > 0 {
  2838. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2839. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10551 || adminUserInfo.Org.Id == 10579 || adminUserInfo.Org.Id == 10580 || adminUserInfo.Org.Id == 10585 {
  2840. if adminUserInfo.Org.Id != 10551 && adminUserInfo.Org.Id != 10579 && adminUserInfo.Org.Id != 10580 && adminUserInfo.Org.Id != 10585 {
  2841. dewater_amount = dewater_amount * 1000
  2842. }
  2843. }
  2844. if dewater_amount <= 0 {
  2845. dewater_amount = 0
  2846. }
  2847. } else {
  2848. dewater_amount = 0
  2849. }
  2850. // 计算透析处方的相关超滤量
  2851. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  2852. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  2853. var lastDialysisPrescribe *models.DialysisPrescription
  2854. var dialysisSolution *models.DialysisSolution
  2855. var dialysisPrescribe *models.DialysisPrescription
  2856. var system_dialysisPrescribe *models.SystemPrescription
  2857. var mode_id int64
  2858. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2859. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  2860. if schedual != nil {
  2861. // 获取透析模版
  2862. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  2863. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  2864. mode_id = schedual.ModeId
  2865. } else {
  2866. // 获取透析模版
  2867. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  2868. if dialysisPrescribe == nil && dialysisSolution != nil {
  2869. mode_id = dialysisSolution.ModeId
  2870. }
  2871. if dialysisPrescribe == nil && dialysisSolution == nil {
  2872. mode_id = 0
  2873. }
  2874. }
  2875. // 插入透析处方
  2876. if dialysisPrescribe == nil && dialysisSolution != nil {
  2877. var newprescribe models.DialysisPrescription
  2878. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2879. newprescribe.PatientId = id
  2880. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2881. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2882. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2883. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2884. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2885. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2886. newprescribe.ModeId = dialysisSolution.ModeId
  2887. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2888. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2889. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2890. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2891. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2892. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2893. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2894. newprescribe.Glucose = dialysisSolution.Glucose
  2895. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2896. newprescribe.Kalium = dialysisSolution.Kalium
  2897. newprescribe.Sodium = dialysisSolution.Sodium
  2898. newprescribe.Calcium = dialysisSolution.Calcium
  2899. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2900. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2901. newprescribe.Conductivity = dialysisSolution.Conductivity
  2902. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2903. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2904. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2905. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2906. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2907. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2908. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2909. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2910. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2911. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2912. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2913. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2914. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2915. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2916. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2917. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2918. newprescribe.CreatedTime = time.Now().Unix()
  2919. newprescribe.UpdatedTime = time.Now().Unix()
  2920. newprescribe.RecordDate = theAssessmentDateTime
  2921. newprescribe.DewaterAmount = dewater_amount
  2922. newprescribe.TargetUltrafiltration = dewater_amount
  2923. newprescribe.Status = 1
  2924. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  2925. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  2926. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2927. newprescribe.Remark = lastDialysisPrescription.Remark
  2928. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2929. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2930. newprescribe.ID = dialysisPrescription.ID
  2931. if dialysisPrescription.ID == 0 {
  2932. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  2933. newprescribe.Sodium = 138
  2934. newprescribe.Bicarbonate = 31.1
  2935. newprescribe.DialysateFlow = 500
  2936. newprescribe.PrescribingNumber = 1
  2937. }
  2938. if adminUserInfo.Org.Id == 10579 {
  2939. newprescribe.Modifier = 0
  2940. newprescribe.Creater = 0
  2941. newprescribe.PrescriptionDoctor = 0
  2942. }
  2943. err := service.AddSigleRecord(&newprescribe)
  2944. //记录日志
  2945. byterequest, _ := json.Marshal(newprescribe)
  2946. prescriptionLog := models.XtDialysisPrescriptionLog{
  2947. UserOrgId: adminUserInfo.Org.Id,
  2948. Ctime: time.Now().Unix(),
  2949. Mtime: 0,
  2950. ErrLog: string(byterequest),
  2951. AdminUserId: adminUserInfo.AdminUser.Id,
  2952. RecordDate: newprescribe.RecordDate,
  2953. PatientId: id,
  2954. Source: "手机端新增透前评估插入处方",
  2955. Status: 1,
  2956. }
  2957. service.CreatePrescriptionLog(prescriptionLog)
  2958. //获取key,清空redis
  2959. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2960. redis := service.RedisClient()
  2961. //清空key 值
  2962. redis.Set(key, "", time.Second)
  2963. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2964. //清空key 值
  2965. redis.Set(keyOne, "", time.Second)
  2966. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2967. //清空key 值
  2968. redis.Set(keyTwo, "", time.Second)
  2969. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2970. redis.Set(keySix, "", time.Second)
  2971. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2972. redis.Set(keySeven, "", time.Second)
  2973. if err != nil {
  2974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2975. }
  2976. } else {
  2977. if adminUserInfo.Org.Id == 10340 {
  2978. newprescribe.Sodium = 138
  2979. newprescribe.Bicarbonate = 31.1
  2980. newprescribe.DialysateFlow = 500
  2981. }
  2982. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2983. //
  2984. if appRole.UserType == 2 || appRole.UserType == 1 {
  2985. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2986. if adminUserInfo.Org.Id == 9882 {
  2987. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2988. }
  2989. }
  2990. err := service.UpDateDialysisPrescription(&newprescribe)
  2991. //记录日志
  2992. byterequest, _ := json.Marshal(newprescribe)
  2993. prescriptionLog := models.XtDialysisPrescriptionLog{
  2994. UserOrgId: adminUserInfo.Org.Id,
  2995. Ctime: time.Now().Unix(),
  2996. Mtime: 0,
  2997. ErrLog: string(byterequest),
  2998. AdminUserId: adminUserInfo.AdminUser.Id,
  2999. RecordDate: newprescribe.RecordDate,
  3000. PatientId: id,
  3001. Source: "手机端新增透前评估插入处方",
  3002. Status: 1,
  3003. }
  3004. service.CreatePrescriptionLog(prescriptionLog)
  3005. //获取key,清空redis
  3006. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3007. redis := service.RedisClient()
  3008. //清空key 值
  3009. redis.Set(key, "", time.Second)
  3010. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3011. //清空key 值
  3012. redis.Set(keyOne, "", time.Second)
  3013. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3014. //清空key 值
  3015. redis.Set(keyTwo, "", time.Second)
  3016. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3017. redis.Set(keySix, "", time.Second)
  3018. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3019. redis.Set(keySeven, "", time.Second)
  3020. if err != nil {
  3021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3022. }
  3023. }
  3024. }
  3025. if dialysisPrescribe == nil && dialysisSolution == nil {
  3026. if lastDialysisPrescribe != nil {
  3027. var newprescribe models.DialysisPrescription
  3028. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3029. newprescribe.PatientId = id
  3030. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  3031. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  3032. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  3033. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  3034. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  3035. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  3036. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  3037. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  3038. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  3039. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  3040. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  3041. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  3042. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  3043. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  3044. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  3045. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  3046. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  3047. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  3048. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  3049. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  3050. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  3051. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  3052. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  3053. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  3054. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  3055. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  3056. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  3057. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  3058. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  3059. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  3060. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  3061. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  3062. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  3063. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  3064. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  3065. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  3066. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  3067. newprescribe.CreatedTime = time.Now().Unix()
  3068. newprescribe.UpdatedTime = time.Now().Unix()
  3069. newprescribe.RecordDate = theAssessmentDateTime
  3070. newprescribe.DewaterAmount = dewater_amount
  3071. newprescribe.TargetUltrafiltration = dewater_amount
  3072. newprescribe.Status = 1
  3073. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  3074. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  3075. if dialysisSolution != nil && dialysisSolution.DialysisStrainer != "" {
  3076. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  3077. }
  3078. newprescribe.Remark = lastDialysisPrescription.Remark
  3079. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  3080. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3081. newprescribe.ID = dialysisPrescription.ID
  3082. if dialysisPrescription.ID == 0 {
  3083. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3084. newprescribe.Sodium = 138
  3085. newprescribe.Bicarbonate = 31.1
  3086. newprescribe.DialysateFlow = 500
  3087. }
  3088. if adminUserInfo.Org.Id == 10579 {
  3089. newprescribe.Modifier = 0
  3090. newprescribe.Creater = 0
  3091. newprescribe.PrescriptionDoctor = 0
  3092. }
  3093. err := service.AddSigleRecord(&newprescribe)
  3094. //记录日志
  3095. byterequest, _ := json.Marshal(newprescribe)
  3096. prescriptionLog := models.XtDialysisPrescriptionLog{
  3097. UserOrgId: adminUserInfo.Org.Id,
  3098. Ctime: time.Now().Unix(),
  3099. Mtime: 0,
  3100. ErrLog: string(byterequest),
  3101. AdminUserId: adminUserInfo.AdminUser.Id,
  3102. RecordDate: newprescribe.RecordDate,
  3103. PatientId: id,
  3104. Source: "手机端新增透前评估插入处方",
  3105. Status: 1,
  3106. }
  3107. service.CreatePrescriptionLog(prescriptionLog)
  3108. //获取key,清空redis
  3109. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3110. redis := service.RedisClient()
  3111. //清空key 值
  3112. redis.Set(key, "", time.Second)
  3113. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3114. //清空key 值
  3115. redis.Set(keyOne, "", time.Second)
  3116. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3117. //清空key 值
  3118. redis.Set(keyTwo, "", time.Second)
  3119. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3120. redis.Set(keySix, "", time.Second)
  3121. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3122. redis.Set(keySeven, "", time.Second)
  3123. if err != nil {
  3124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3125. }
  3126. } else {
  3127. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3128. //
  3129. if appRole.UserType == 2 || appRole.UserType == 1 {
  3130. if adminUserInfo.Org.Id == 10579 {
  3131. newprescribe.Modifier = 0
  3132. newprescribe.Creater = 0
  3133. newprescribe.PrescriptionDoctor = 0
  3134. } else {
  3135. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3136. }
  3137. if adminUserInfo.Org.Id == 9882 {
  3138. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3139. }
  3140. }
  3141. err := service.UpDateDialysisPrescription(&newprescribe)
  3142. //记录日志
  3143. byterequest, _ := json.Marshal(newprescribe)
  3144. prescriptionLog := models.XtDialysisPrescriptionLog{
  3145. UserOrgId: adminUserInfo.Org.Id,
  3146. Ctime: time.Now().Unix(),
  3147. Mtime: 0,
  3148. ErrLog: string(byterequest),
  3149. AdminUserId: adminUserInfo.AdminUser.Id,
  3150. RecordDate: newprescribe.RecordDate,
  3151. PatientId: id,
  3152. Source: "手机端新增透前评估插入处方",
  3153. Status: 1,
  3154. }
  3155. service.CreatePrescriptionLog(prescriptionLog)
  3156. //获取key,清空redis
  3157. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3158. redis := service.RedisClient()
  3159. //清空key 值
  3160. redis.Set(key, "", time.Second)
  3161. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3162. //清空key 值
  3163. redis.Set(keyOne, "", time.Second)
  3164. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3165. //清空key 值
  3166. redis.Set(keyTwo, "", time.Second)
  3167. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3168. redis.Set(keySix, "", time.Second)
  3169. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3170. redis.Set(keySeven, "", time.Second)
  3171. if err != nil {
  3172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3173. }
  3174. }
  3175. if err != nil {
  3176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3177. }
  3178. } else if system_dialysisPrescribe != nil {
  3179. var newprescribe models.DialysisPrescription
  3180. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3181. newprescribe.PatientId = id
  3182. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  3183. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  3184. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  3185. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  3186. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  3187. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  3188. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  3189. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  3190. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  3191. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  3192. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  3193. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  3194. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  3195. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  3196. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  3197. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  3198. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  3199. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  3200. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  3201. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  3202. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  3203. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  3204. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  3205. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  3206. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  3207. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  3208. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  3209. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  3210. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  3211. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  3212. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  3213. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  3214. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  3215. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  3216. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  3217. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  3218. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  3219. newprescribe.CreatedTime = time.Now().Unix()
  3220. newprescribe.UpdatedTime = time.Now().Unix()
  3221. newprescribe.RecordDate = theAssessmentDateTime
  3222. newprescribe.DewaterAmount = dewater_amount
  3223. newprescribe.TargetUltrafiltration = dewater_amount
  3224. newprescribe.Status = 1
  3225. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  3226. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  3227. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  3228. newprescribe.Remark = lastDialysisPrescription.Remark
  3229. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  3230. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3231. newprescribe.ID = dialysisPrescription.ID
  3232. if dialysisPrescription.ID == 0 {
  3233. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3234. newprescribe.Sodium = 138
  3235. newprescribe.Bicarbonate = 31.1
  3236. newprescribe.DialysateFlow = 500
  3237. }
  3238. if adminUserInfo.Org.Id == 10579 {
  3239. newprescribe.Modifier = 0
  3240. newprescribe.Creater = 0
  3241. newprescribe.PrescriptionDoctor = 0
  3242. }
  3243. err := service.AddSigleRecord(&newprescribe)
  3244. //记录日志
  3245. byterequest, _ := json.Marshal(newprescribe)
  3246. prescriptionLog := models.XtDialysisPrescriptionLog{
  3247. UserOrgId: adminUserInfo.Org.Id,
  3248. Ctime: time.Now().Unix(),
  3249. Mtime: 0,
  3250. ErrLog: string(byterequest),
  3251. AdminUserId: adminUserInfo.AdminUser.Id,
  3252. RecordDate: newprescribe.RecordDate,
  3253. PatientId: id,
  3254. Source: "手机端新增透前评估插入处方",
  3255. Status: 1,
  3256. }
  3257. service.CreatePrescriptionLog(prescriptionLog)
  3258. //获取key,清空redis
  3259. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3260. redis := service.RedisClient()
  3261. //清空key 值
  3262. redis.Set(key, "", time.Second)
  3263. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3264. //清空key 值
  3265. redis.Set(keyOne, "", time.Second)
  3266. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3267. //清空key 值
  3268. redis.Set(keyTwo, "", time.Second)
  3269. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3270. redis.Set(keySix, "", time.Second)
  3271. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3272. redis.Set(keySeven, "", time.Second)
  3273. if err != nil {
  3274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3275. }
  3276. } else {
  3277. if adminUserInfo.Org.Id == 10340 {
  3278. newprescribe.Sodium = 138
  3279. newprescribe.Bicarbonate = 31.1
  3280. newprescribe.DialysateFlow = 500
  3281. }
  3282. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3283. //
  3284. if appRole.UserType == 2 || appRole.UserType == 1 {
  3285. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3286. if adminUserInfo.Org.Id == 9882 {
  3287. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3288. }
  3289. }
  3290. err := service.UpDateDialysisPrescription(&newprescribe)
  3291. //记录日志
  3292. byterequest, _ := json.Marshal(newprescribe)
  3293. prescriptionLog := models.XtDialysisPrescriptionLog{
  3294. UserOrgId: adminUserInfo.Org.Id,
  3295. Ctime: time.Now().Unix(),
  3296. Mtime: 0,
  3297. ErrLog: string(byterequest),
  3298. AdminUserId: adminUserInfo.AdminUser.Id,
  3299. RecordDate: newprescribe.RecordDate,
  3300. PatientId: id,
  3301. Source: "手机端新增透前评估插入处方",
  3302. Status: 1,
  3303. }
  3304. service.CreatePrescriptionLog(prescriptionLog)
  3305. //获取key,清空redis
  3306. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3307. redis := service.RedisClient()
  3308. //清空key 值
  3309. redis.Set(key, "", time.Second)
  3310. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3311. //清空key 值
  3312. redis.Set(keyOne, "", time.Second)
  3313. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3314. //清空key 值
  3315. redis.Set(keyTwo, "", time.Second)
  3316. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3317. redis.Set(keySix, "", time.Second)
  3318. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3319. redis.Set(keySeven, "", time.Second)
  3320. if err != nil {
  3321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3322. }
  3323. }
  3324. if err != nil {
  3325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3326. }
  3327. } else {
  3328. var newprescribe models.DialysisPrescription
  3329. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3330. newprescribe.PatientId = id
  3331. newprescribe.ModeId = mode_id
  3332. newprescribe.CreatedTime = time.Now().Unix()
  3333. newprescribe.UpdatedTime = time.Now().Unix()
  3334. newprescribe.RecordDate = theAssessmentDateTime
  3335. newprescribe.DewaterAmount = dewater_amount
  3336. newprescribe.TargetUltrafiltration = dewater_amount
  3337. newprescribe.Status = 1
  3338. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3339. if dialysisPrescription.ID > 0 {
  3340. newprescribe.ID = dialysisPrescription.ID
  3341. }
  3342. if dialysisPrescription.ID == 0 {
  3343. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3344. newprescribe.Sodium = 138
  3345. newprescribe.Bicarbonate = 31.1
  3346. newprescribe.DialysateFlow = 500
  3347. }
  3348. if adminUserInfo.Org.Id == 10579 {
  3349. newprescribe.Modifier = 0
  3350. newprescribe.Creater = 0
  3351. newprescribe.PrescriptionDoctor = 0
  3352. }
  3353. err := service.AddSigleRecord(&newprescribe)
  3354. //获取key,清空redis
  3355. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3356. redis := service.RedisClient()
  3357. //清空key 值
  3358. redis.Set(key, "", time.Second)
  3359. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3360. //清空key 值
  3361. redis.Set(keyOne, "", time.Second)
  3362. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3363. //清空key 值
  3364. redis.Set(keyTwo, "", time.Second)
  3365. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3366. redis.Set(keySix, "", time.Second)
  3367. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3368. redis.Set(keySeven, "", time.Second)
  3369. if err != nil {
  3370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3371. }
  3372. } else {
  3373. if adminUserInfo.Org.Id == 10340 {
  3374. newprescribe.Sodium = 138
  3375. newprescribe.Bicarbonate = 31.1
  3376. newprescribe.DialysateFlow = 500
  3377. }
  3378. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3379. //
  3380. if appRole.UserType == 2 || appRole.UserType == 1 {
  3381. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3382. if adminUserInfo.Org.Id == 9882 {
  3383. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3384. }
  3385. }
  3386. if adminUserInfo.Org.Id == 10579 {
  3387. newprescribe.Modifier = 0
  3388. newprescribe.Creater = 0
  3389. newprescribe.PrescriptionDoctor = 0
  3390. }
  3391. err := service.UpDateDialysisPrescription(&newprescribe)
  3392. //记录日志
  3393. byterequest, _ := json.Marshal(newprescribe)
  3394. prescriptionLog := models.XtDialysisPrescriptionLog{
  3395. UserOrgId: adminUserInfo.Org.Id,
  3396. Ctime: time.Now().Unix(),
  3397. Mtime: 0,
  3398. ErrLog: string(byterequest),
  3399. AdminUserId: adminUserInfo.AdminUser.Id,
  3400. RecordDate: newprescribe.RecordDate,
  3401. PatientId: id,
  3402. Source: "手机端新增透前评估插入处方",
  3403. Status: 1,
  3404. }
  3405. service.CreatePrescriptionLog(prescriptionLog)
  3406. //获取key,清空redis
  3407. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3408. redis := service.RedisClient()
  3409. //清空key 值
  3410. redis.Set(key, "", time.Second)
  3411. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3412. //清空key 值
  3413. redis.Set(keyOne, "", time.Second)
  3414. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3415. //清空key 值
  3416. redis.Set(keyTwo, "", time.Second)
  3417. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3418. redis.Set(keySix, "", time.Second)
  3419. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3420. redis.Set(keySeven, "", time.Second)
  3421. if err != nil {
  3422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3423. }
  3424. }
  3425. if err != nil {
  3426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3427. }
  3428. }
  3429. }
  3430. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  3431. // if dialysisPrescribe != nil {
  3432. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  3433. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  3434. // dialysisPrescribe.DewaterAmount = dewater_amount
  3435. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  3436. // dialysisPrescribe.Status = 1
  3437. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  3438. // if updateErr != nil {
  3439. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3440. // }
  3441. // }
  3442. // 查询信息规挡的设置天数
  3443. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3444. if infor.ID > 0 && infor.WeekDay > 0 {
  3445. var cha_time int64
  3446. timeNowStr := time.Now().Format("2006-01-02")
  3447. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3448. //今日的日期减去设置的日期
  3449. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3450. if cha_time >= evaluation.AssessmentDate {
  3451. //查询审核是否允许
  3452. infor, _ := service.GetDialysisInformationByRecordDate(id, evaluation.AssessmentDate, adminUserInfo.Org.Id, 3)
  3453. //申请状态不允许的情况 拒绝修改
  3454. if infor.ApplicationStatus != 1 {
  3455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3456. return
  3457. }
  3458. }
  3459. }
  3460. //针对长沙南雅的问题
  3461. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10164 {
  3462. if len(evaluation.SymptomBeforeDialysis) == 0 {
  3463. predialysisEvaluation, _ := service.GetPredialysisEvaluation(id, adminUserInfo.Org.Id)
  3464. evaluation.SymptomBeforeDialysis = predialysisEvaluation.SymptomBeforeDialysis
  3465. }
  3466. }
  3467. err = service.UpadatePredialysisEvaluation(&evaluation)
  3468. //记录日志
  3469. byterequest, _ := json.Marshal(evaluation)
  3470. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  3471. UserOrgId: evaluation.UserOrgId,
  3472. AdminUserId: adminUserInfo.AdminUser.Id,
  3473. ErrLog: string(byterequest),
  3474. PatientId: evaluation.PatientId,
  3475. RecordDate: evaluation.AssessmentDate,
  3476. Ctime: time.Now().Unix(),
  3477. Mtime: 0,
  3478. Status: 1,
  3479. Source: "手机端保存透前评估",
  3480. }
  3481. service.CreateBeforLog(beforeDislysisLog)
  3482. finish := models.XtDialysisFinish{
  3483. IsFinish: 1,
  3484. UserOrgId: adminUserInfo.Org.Id,
  3485. Status: 1,
  3486. Ctime: time.Now().Unix(),
  3487. Mtime: 0,
  3488. Module: 3,
  3489. RecordDate: evaluation.AssessmentDate,
  3490. Sourse: 1,
  3491. PatientId: id,
  3492. }
  3493. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3, id)
  3494. if dialysisFinish.ID == 0 {
  3495. service.CreateDialysisFinish(finish)
  3496. }
  3497. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  3498. redis := service.RedisClient()
  3499. defer redis.Close()
  3500. //清空key 值
  3501. redis.Set(key, "", time.Second)
  3502. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  3503. redis.Set(keyOne, "", time.Second)
  3504. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3505. redis.Set(keyTwo, "", time.Second)
  3506. if err != nil {
  3507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  3508. return
  3509. }
  3510. c.ServeSuccessJSON(map[string]interface{}{
  3511. "msg": "ok",
  3512. "evaluation": evaluation,
  3513. })
  3514. return
  3515. }
  3516. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3517. dataBody := make(map[string]interface{}, 0)
  3518. err := json.Unmarshal(data, &dataBody)
  3519. utils.InfoLog(string(data))
  3520. if err != nil {
  3521. utils.ErrorLog(err.Error())
  3522. code = enums.ErrorCodeParamWrong
  3523. return
  3524. }
  3525. // if method == "create" {
  3526. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  3527. utils.ErrorLog("mode")
  3528. code = enums.ErrorCodeParamWrong
  3529. return
  3530. }
  3531. mode := int64(dataBody["mode"].(float64))
  3532. if mode <= 0 {
  3533. utils.ErrorLog("mode <= 0")
  3534. code = enums.ErrorCodeParamWrong
  3535. return
  3536. }
  3537. solution.ModeId = mode
  3538. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  3539. utils.ErrorLog("mode_name")
  3540. code = enums.ErrorCodeParamWrong
  3541. return
  3542. }
  3543. modeName, _ := dataBody["mode_name"].(string)
  3544. if len(modeName) == 0 {
  3545. utils.ErrorLog("len(mode_name) == 0")
  3546. code = enums.ErrorCodeParamWrong
  3547. return
  3548. }
  3549. solution.ModeName = modeName
  3550. solution.Name = modeName
  3551. // }
  3552. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3553. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3554. solution.DialysisDuration = dialysisDuration
  3555. }
  3556. if dataBody["dialysis_duration"] != nil {
  3557. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3558. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3559. solution.DialysisDuration = dialysisDuration
  3560. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  3561. dialysisDuration := dataBody["dialysis_duration"].(float64)
  3562. solution.DialysisDuration = dialysisDuration
  3563. }
  3564. }
  3565. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3566. dialyzer := int64(dataBody["dialyzer"].(float64))
  3567. solution.Dialyzer = dialyzer
  3568. }
  3569. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3570. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3571. solution.PerfusionApparatus = perfusionApparatus
  3572. }
  3573. if dataBody["blood_flow_volume"] != nil {
  3574. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3575. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3576. solution.BloodFlowVolume = bloodFlowVolume
  3577. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  3578. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  3579. solution.BloodFlowVolume = bloodFlowVolume
  3580. }
  3581. }
  3582. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3583. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3584. solution.HemodialysisMachine = hemodialysisMachine
  3585. }
  3586. if dataBody["dewater"] != nil {
  3587. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3588. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3589. solution.Dewater = dewater
  3590. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  3591. dewater := dataBody["dewater"].(float64)
  3592. solution.Dewater = dewater
  3593. }
  3594. }
  3595. if dataBody["replacement_total"] != nil {
  3596. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3597. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3598. solution.ReplacementTotal = replacementTotal
  3599. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  3600. replacementTotal := dataBody["replacement_total"].(float64)
  3601. solution.ReplacementTotal = replacementTotal
  3602. }
  3603. }
  3604. if dataBody["displace_liqui"] != nil {
  3605. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3606. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3607. solution.DisplaceLiqui = displaceLiqui
  3608. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  3609. displaceLiqui := dataBody["displace_liqui"].(float64)
  3610. solution.DisplaceLiqui = displaceLiqui
  3611. }
  3612. }
  3613. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3614. replacementWay := int64(dataBody["replacement_way"].(float64))
  3615. solution.ReplacementWay = replacementWay
  3616. }
  3617. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3618. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3619. solution.Anticoagulant = anticoagulant
  3620. }
  3621. if dataBody["anticoagulant_shouji"] != nil {
  3622. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3623. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3624. solution.AnticoagulantShouji = anticoagulantShouji
  3625. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  3626. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  3627. solution.AnticoagulantShouji = anticoagulantShouji
  3628. }
  3629. }
  3630. if dataBody["anticoagulant_weichi"] != nil {
  3631. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3632. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3633. solution.AnticoagulantWeichi = anticoagulantWeichi
  3634. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  3635. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  3636. solution.AnticoagulantWeichi = anticoagulantWeichi
  3637. }
  3638. }
  3639. if dataBody["anticoagulant_zongliang"] != nil {
  3640. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3641. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3642. solution.AnticoagulantZongliang = anticoagulantZongliang
  3643. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  3644. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  3645. solution.AnticoagulantZongliang = anticoagulantZongliang
  3646. }
  3647. }
  3648. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3649. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3650. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3651. }
  3652. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3653. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3654. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3655. }
  3656. if dataBody["kalium"] != nil {
  3657. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3658. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3659. solution.Kalium = kalium
  3660. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  3661. kalium := dataBody["kalium"].(float64)
  3662. solution.Kalium = kalium
  3663. }
  3664. }
  3665. if dataBody["sodium"] != nil {
  3666. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3667. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3668. solution.Sodium = sodium
  3669. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  3670. sodium := dataBody["sodium"].(float64)
  3671. solution.Sodium = sodium
  3672. }
  3673. }
  3674. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3675. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3676. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3677. solution.Calcium = calcium
  3678. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  3679. calcium := dataBody["calcium"].(float64)
  3680. solution.Calcium = calcium
  3681. }
  3682. }
  3683. if dataBody["bicarbonate"] != nil {
  3684. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3685. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3686. solution.Bicarbonate = bicarbonate
  3687. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  3688. bicarbonate := dataBody["bicarbonate"].(float64)
  3689. solution.Bicarbonate = bicarbonate
  3690. }
  3691. }
  3692. if dataBody["glucose"] != nil {
  3693. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3694. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3695. solution.Glucose = glucose
  3696. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  3697. glucose := dataBody["glucose"].(float64)
  3698. solution.Glucose = glucose
  3699. }
  3700. }
  3701. // if dataBody["dry_weight"] != nil {
  3702. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3703. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3704. // solution.DryWeight = dryWeight
  3705. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  3706. // dryWeight := dataBody["dry_weight"].(float64)
  3707. // solution.DryWeight = dryWeight
  3708. // }
  3709. // }
  3710. if dataBody["dialysate_flow"] != nil {
  3711. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3712. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3713. solution.DialysateFlow = dialysateFlow
  3714. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  3715. dialysateFlow := dataBody["dialysate_flow"].(float64)
  3716. solution.DialysateFlow = dialysateFlow
  3717. }
  3718. }
  3719. if dataBody["dialysate_temperature"] != nil {
  3720. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3721. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3722. solution.DialysateTemperature = dialysateTemperature
  3723. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  3724. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  3725. solution.DialysateTemperature = dialysateTemperature
  3726. }
  3727. }
  3728. if dataBody["conductivity"] != nil {
  3729. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3730. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3731. solution.Conductivity = conductivity
  3732. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  3733. conductivity := dataBody["conductivity"].(float64)
  3734. solution.Conductivity = conductivity
  3735. }
  3736. }
  3737. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3738. remark := dataBody["remark"].(string)
  3739. solution.Remark = remark
  3740. }
  3741. if dataBody["dialysis_duration_hour"] != nil {
  3742. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3743. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  3744. solution.DialysisDurationHour = dialysisDurationHour
  3745. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  3746. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  3747. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3748. }
  3749. }
  3750. if dataBody["dialysis_duration_minute"] != nil {
  3751. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3752. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  3753. solution.DialysisDurationMinute = dialysisDurationMinute
  3754. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  3755. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  3756. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3757. }
  3758. }
  3759. if dataBody["target_ultrafiltration"] != nil {
  3760. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3761. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3762. solution.TargetUltrafiltration = targetUltrafiltration
  3763. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  3764. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  3765. solution.TargetUltrafiltration = targetUltrafiltration
  3766. }
  3767. }
  3768. if dataBody["dialysate_formulation"] != nil {
  3769. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  3770. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  3771. solution.DialysateFormulation = dialysateFormulation
  3772. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3773. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  3774. solution.DialysateFormulation = int64(dialysateFormulation)
  3775. }
  3776. }
  3777. return
  3778. }
  3779. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  3780. dataBody := make(map[string]interface{}, 0)
  3781. err := json.Unmarshal(data, &dataBody)
  3782. utils.InfoLog(string(data))
  3783. if err != nil {
  3784. utils.ErrorLog(err.Error())
  3785. code = enums.ErrorCodeParamWrong
  3786. return
  3787. }
  3788. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  3789. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  3790. evaluation.WeightBefore = weightVefore
  3791. }
  3792. // fmt.Println(dataBody["dry_weight"])
  3793. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  3794. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3795. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3796. fmt.Println(additionalWeight)
  3797. evaluation.DryWeight = additionalWeight
  3798. }
  3799. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  3800. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  3801. fmt.Println(additionalWeight)
  3802. evaluation.AdditionalWeight = additionalWeight
  3803. }
  3804. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  3805. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  3806. evaluation.Temperature = Temperature
  3807. }
  3808. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  3809. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  3810. evaluation.SystolicBloodPressure = systolicBloodPressure
  3811. }
  3812. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  3813. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  3814. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  3815. }
  3816. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  3817. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  3818. evaluation.PulseFrequency = pulseFrequency
  3819. }
  3820. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  3821. breathingRate := dataBody["breathing_rate"].(string)
  3822. evaluation.BreathingRate = breathingRate
  3823. }
  3824. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  3825. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  3826. evaluation.LastPostDialysis = lastPostDialysis
  3827. }
  3828. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  3829. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  3830. evaluation.DialysisInterphase = dialysisInterphase
  3831. }
  3832. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  3833. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  3834. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  3835. }
  3836. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  3837. catheter, _ := dataBody["catheter"].(string)
  3838. evaluation.Catheter = catheter
  3839. }
  3840. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  3841. catheter_bend := int(dataBody["catheter_bend"].(float64))
  3842. evaluation.CatheterBend = catheter_bend
  3843. }
  3844. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  3845. Complication, _ := dataBody["complication"].(string)
  3846. evaluation.Complication = Complication
  3847. }
  3848. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3849. remark := dataBody["remark"].(string)
  3850. evaluation.Remark = remark
  3851. }
  3852. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  3853. machine_type := dataBody["machine_type"].(string)
  3854. evaluation.MachineType = machine_type
  3855. }
  3856. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  3857. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  3858. evaluation.BloodAccessPartId = blood_access_part_id
  3859. }
  3860. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  3861. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  3862. // evaluation.BloodAccessPartId = blood_access_part_id
  3863. //}
  3864. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  3865. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  3866. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  3867. }
  3868. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  3869. internal_fistula, _ := dataBody["internal_fistula"].(string)
  3870. evaluation.InternalFistula = internal_fistula
  3871. }
  3872. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  3873. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  3874. evaluation.InternalFistulaSkin = internal_fistula_skin
  3875. }
  3876. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  3877. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  3878. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  3879. evaluation.IsHemorrhage = is_hemorrhage
  3880. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  3881. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  3882. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  3883. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  3884. is_hemorrhage = 0
  3885. }
  3886. evaluation.IsHemorrhage = is_hemorrhage
  3887. if is_hemorrhage == 1 {
  3888. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  3889. hemorrhage, _ := dataBody["hemorrhage"].(string)
  3890. evaluation.Hemorrhage = hemorrhage
  3891. }
  3892. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  3893. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  3894. evaluation.HemorrhageOther = hemorrhage_other
  3895. }
  3896. }
  3897. } else {
  3898. evaluation.IsHemorrhage = 0
  3899. }
  3900. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  3901. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  3902. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  3903. }
  3904. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  3905. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  3906. evaluation.InternalFistulaOther = internal_fistula_other
  3907. }
  3908. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  3909. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  3910. evaluation.BloodAccessNoise = blood_access_noise
  3911. }
  3912. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  3913. //puncture_way := int64(dataBody["puncture_way"].(float64))
  3914. puncture_way := dataBody["puncture_way"].(string)
  3915. evaluation.PunctureWay = puncture_way
  3916. }
  3917. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  3918. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  3919. evaluation.VenousCatheterization = venous_catheterization
  3920. }
  3921. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  3922. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  3923. evaluation.VenousCatheterizationPart = venous_catheterization_part
  3924. }
  3925. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  3926. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  3927. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  3928. }
  3929. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  3930. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  3931. evaluation.DuctusArantii = ductus_arantii
  3932. }
  3933. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  3934. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  3935. evaluation.EmergencyTreatment = emergency_treatment
  3936. }
  3937. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  3938. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  3939. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  3940. }
  3941. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  3942. dialysis_count, _ := dataBody["dialysis_count"].(string)
  3943. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  3944. evaluation.DialysisCount = dialysis_count
  3945. }
  3946. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  3947. is_infect, _ := dataBody["is_infect"].(string)
  3948. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  3949. evaluation.IsInfect = infect
  3950. }
  3951. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  3952. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  3953. evaluation.Exposed = exposed
  3954. }
  3955. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  3956. skin, _ := dataBody["skin"].(string)
  3957. //skins, _ := strconv.ParseInt(skin, 10, 64)
  3958. evaluation.Skin = skin
  3959. }
  3960. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  3961. skin_other, _ := dataBody["skin_other"].(string)
  3962. evaluation.SkinOther = skin_other
  3963. }
  3964. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  3965. infect_other, _ := dataBody["infect_other"].(string)
  3966. evaluation.InfectOther = infect_other
  3967. }
  3968. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  3969. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  3970. evaluation.DuctusArantiiOther = ductus_arantii_other
  3971. }
  3972. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  3973. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  3974. evaluation.PunctureNeedle = punctureNeedle
  3975. }
  3976. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  3977. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  3978. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  3979. }
  3980. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  3981. pinholing := dataBody["pinholing"].(string)
  3982. evaluation.Phinholing = pinholing
  3983. }
  3984. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  3985. catheter_suture := dataBody["catheter_suture"].(string)
  3986. evaluation.CatheterSuture = catheter_suture
  3987. }
  3988. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  3989. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  3990. evaluation.CatheterSutureOther = catheter_suture_other
  3991. }
  3992. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  3993. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  3994. evaluation.UrineVolume = urine_volume
  3995. }
  3996. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  3997. edema := dataBody["edema"].(string)
  3998. evaluation.Edema = edema
  3999. }
  4000. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  4001. specialTreatment := dataBody["special_treatment"].(string)
  4002. evaluation.SpecialTreatment = specialTreatment
  4003. }
  4004. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  4005. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  4006. evaluation.CatheterMaintenance = catheter_maintenance
  4007. }
  4008. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  4009. thromubusType := int64(dataBody["thromubus_type"].(float64))
  4010. evaluation.ThromubusType = thromubusType
  4011. }
  4012. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  4013. thrombus_av := dataBody["thrombus_av"].(string)
  4014. evaluation.ThrombusAv = thrombus_av
  4015. }
  4016. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  4017. thromubus_a := dataBody["thromubus_a"].(string)
  4018. evaluation.ThromubusA = thromubus_a
  4019. }
  4020. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  4021. thromubus_v := dataBody["thromubus_v"].(string)
  4022. evaluation.ThromubusV = thromubus_v
  4023. }
  4024. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  4025. dehydration := dataBody["dehydration"].(string)
  4026. evaluation.Dehydration = dehydration
  4027. }
  4028. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  4029. period := int64(dataBody["period"].(float64))
  4030. evaluation.Period = period
  4031. }
  4032. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  4033. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  4034. evaluation.EstimatedFoodIntake = estimated_food_intake
  4035. }
  4036. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  4037. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  4038. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  4039. }
  4040. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  4041. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  4042. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  4043. }
  4044. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  4045. urea_befor := dataBody["urea_befor"].(string)
  4046. evaluation.UreaBefor = urea_befor
  4047. }
  4048. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  4049. suction := dataBody["suction"].(string)
  4050. evaluation.Suction = suction
  4051. }
  4052. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  4053. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  4054. evaluation.WeightBeforRemake = weight_befor_remake
  4055. }
  4056. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  4057. height := dataBody["height"].(string)
  4058. evaluation.Height = height
  4059. }
  4060. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  4061. age := dataBody["age"].(string)
  4062. evaluation.Age = age
  4063. }
  4064. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  4065. his_department := dataBody["his_department"].(string)
  4066. evaluation.HisDepartment = his_department
  4067. }
  4068. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  4069. his_bed := dataBody["his_bed"].(string)
  4070. evaluation.HisBed = his_bed
  4071. }
  4072. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  4073. point_puncture := dataBody["point_puncture"].(string)
  4074. evaluation.PointPuncture = point_puncture
  4075. }
  4076. if dataBody["catheter_evaluation_program"] != nil && reflect.TypeOf(dataBody["catheter_evaluation_program"]).String() == "string" {
  4077. catheter_evaluation_program := dataBody["catheter_evaluation_program"].(string)
  4078. evaluation.CatheterEvaluationProgram = catheter_evaluation_program
  4079. }
  4080. if dataBody["skin_site_catheterization"] != nil && reflect.TypeOf(dataBody["skin_site_catheterization"]).String() == "string" {
  4081. skin_site_catheterization := dataBody["skin_site_catheterization"].(string)
  4082. evaluation.SkinSiteCatheterization = skin_site_catheterization
  4083. }
  4084. if dataBody["whether_unobstructed"] != nil && reflect.TypeOf(dataBody["whether_unobstructed"]).String() == "float64" {
  4085. whether_unobstructed := int64(dataBody["whether_unobstructed"].(float64))
  4086. evaluation.WhetherUnobstructed = whether_unobstructed
  4087. }
  4088. if dataBody["lien_necessary"] != nil && reflect.TypeOf(dataBody["lien_necessary"]).String() == "float64" {
  4089. lien_necessary := int64(dataBody["lien_necessary"].(float64))
  4090. evaluation.LienNecessary = lien_necessary
  4091. }
  4092. if dataBody["pathway_formation_time"] != nil && reflect.TypeOf(dataBody["pathway_formation_time"]).String() == "string" {
  4093. pathway_formation_time := dataBody["pathway_formation_time"].(string)
  4094. timeLayout := "2006-01-02"
  4095. loc, _ := time.LoadLocation("Local")
  4096. var startTime int64
  4097. if len(pathway_formation_time) > 0 {
  4098. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  4099. startTime = theTime.Unix()
  4100. }
  4101. evaluation.PathwayFormationTime = startTime
  4102. }
  4103. if dataBody["befor_symptoms"] != nil && reflect.TypeOf(dataBody["befor_symptoms"]).String() == "string" {
  4104. befor_symptoms := dataBody["befor_symptoms"].(string)
  4105. evaluation.BeforSymptoms = befor_symptoms
  4106. }
  4107. if dataBody["washing_time"] != nil && reflect.TypeOf(dataBody["washing_time"]).String() == "string" {
  4108. washing_time, _ := dataBody["washing_time"].(string)
  4109. evaluation.WashingTime = washing_time
  4110. }
  4111. if dataBody["warsh_count"] != nil && reflect.TypeOf(dataBody["warsh_count"]).String() == "string" {
  4112. warsh_count, _ := dataBody["warsh_count"].(string)
  4113. evaluation.WarshCount = warsh_count
  4114. }
  4115. if dataBody["puncture_needle_direction"] != nil && reflect.TypeOf(dataBody["puncture_needle_direction"]).String() == "string" {
  4116. puncture_needle_direction, _ := dataBody["puncture_needle_direction"].(string)
  4117. evaluation.PunctureNeedleDirection = puncture_needle_direction
  4118. }
  4119. if dataBody["symptom_before_dialysis_other"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis_other"]).String() == "string" {
  4120. symptom_before_dialysis_other, _ := dataBody["symptom_before_dialysis_other"].(string)
  4121. evaluation.SymptomBeforeDialysisOther = symptom_before_dialysis_other
  4122. }
  4123. return
  4124. }
  4125. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  4126. dataBody := make(map[string]interface{}, 0)
  4127. err := json.Unmarshal(data, &dataBody)
  4128. if err != nil {
  4129. utils.ErrorLog(err.Error())
  4130. code = enums.ErrorCodeParamWrong
  4131. return
  4132. }
  4133. timeLayout := "2006-01-02"
  4134. loc, _ := time.LoadLocation("Local")
  4135. isChild := false
  4136. if action == "create" {
  4137. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4138. utils.ErrorLog("advice_type")
  4139. code = enums.ErrorCodeParamWrong
  4140. return
  4141. }
  4142. adviceType := int64(dataBody["advice_type"].(float64))
  4143. if adviceType != 1 && adviceType != 2 {
  4144. utils.ErrorLog("advice_type != 1&&2")
  4145. code = enums.ErrorCodeParamWrong
  4146. return
  4147. }
  4148. advice.AdviceType = adviceType
  4149. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4150. utils.ErrorLog("advice_date")
  4151. code = enums.ErrorCodeParamWrong
  4152. return
  4153. }
  4154. adviceDate, _ := dataBody["advice_date"].(string)
  4155. if len(adviceDate) == 0 {
  4156. utils.ErrorLog("len(adviceDate) == 0")
  4157. code = enums.ErrorCodeParamWrong
  4158. return
  4159. }
  4160. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4161. if err != nil {
  4162. utils.ErrorLog(err.Error())
  4163. code = enums.ErrorCodeParamWrong
  4164. return
  4165. }
  4166. advice.AdviceDate = theTime.Unix()
  4167. advice.RecordDate = theTime.Unix()
  4168. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  4169. parentId := int64(dataBody["parent_id"].(float64))
  4170. advice.ParentId = parentId
  4171. if parentId > 0 {
  4172. isChild = true
  4173. }
  4174. }
  4175. } else {
  4176. isChild = advice.ParentId > 0
  4177. }
  4178. if !isChild {
  4179. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4180. utils.ErrorLog("start_time")
  4181. code = enums.ErrorCodeParamWrong
  4182. return
  4183. }
  4184. startTime, _ := dataBody["start_time"].(string)
  4185. if len(startTime) == 0 {
  4186. utils.ErrorLog("len(start_time) == 0")
  4187. code = enums.ErrorCodeParamWrong
  4188. return
  4189. }
  4190. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  4191. if err != nil {
  4192. utils.ErrorLog(err.Error())
  4193. code = enums.ErrorCodeParamWrong
  4194. return
  4195. }
  4196. advice.StartTime = theTime.Unix()
  4197. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4198. deliveryWay, _ := dataBody["delivery_way"].(string)
  4199. advice.DeliveryWay = deliveryWay
  4200. }
  4201. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4202. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4203. advice.ExecutionFrequency = executionFrequency
  4204. }
  4205. }
  4206. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4207. deliveryWay, _ := dataBody["delivery_way"].(string)
  4208. advice.DeliveryWay = deliveryWay
  4209. }
  4210. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4211. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4212. advice.ExecutionFrequency = executionFrequency
  4213. }
  4214. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  4215. utils.ErrorLog("advice_name")
  4216. code = enums.ErrorCodeParamWrong
  4217. return
  4218. }
  4219. adviceName, _ := dataBody["advice_name"].(string)
  4220. if len(adviceName) == 0 {
  4221. utils.ErrorLog("len(advice_name) == 0")
  4222. code = enums.ErrorCodeParamWrong
  4223. return
  4224. }
  4225. advice.AdviceName = adviceName
  4226. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  4227. adviceDsc, _ := dataBody["advice_desc"].(string)
  4228. advice.AdviceDesc = adviceDsc
  4229. }
  4230. if dataBody["way"] == nil {
  4231. advice.Way = 0
  4232. } else {
  4233. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  4234. way := int64(dataBody["way"].(float64))
  4235. advice.Way = way
  4236. }
  4237. }
  4238. if dataBody["drug_id"] == nil {
  4239. advice.DrugId = 0
  4240. } else {
  4241. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  4242. drug_id := int64(dataBody["drug_id"].(float64))
  4243. advice.DrugId = drug_id
  4244. }
  4245. }
  4246. if dataBody["drug_name_id"] == nil {
  4247. advice.DrugNameId = 0
  4248. } else {
  4249. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  4250. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  4251. advice.DrugNameId = drug_name_id
  4252. }
  4253. }
  4254. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  4255. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  4256. advice.SingleDose = singleDose
  4257. }
  4258. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  4259. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  4260. advice.SingleDoseUnit = singleDoseUnit
  4261. }
  4262. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  4263. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  4264. advice.DrugSpec = drugSpec
  4265. }
  4266. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  4267. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  4268. advice.DrugSpecUnit = drugSpecUnit
  4269. }
  4270. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  4271. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  4272. advice.PrescribingNumber = prescribingNumber
  4273. }
  4274. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  4275. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  4276. advice.PrescribingNumberUnit = prescribingNumberUnit
  4277. }
  4278. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4279. remark, _ := dataBody["remark"].(string)
  4280. advice.Remark = remark
  4281. }
  4282. return
  4283. }
  4284. func (c *PatientApiController) GetPatientEducation() {
  4285. patientID, _ := c.GetInt64("patient_id", 0)
  4286. page, _ := c.GetInt64("page", 0)
  4287. limit, _ := c.GetInt64("limit", 0)
  4288. startTime := c.GetString("start_time", "")
  4289. endTime := c.GetString("end_time", "")
  4290. if page <= 0 {
  4291. page = 1
  4292. }
  4293. if limit <= 0 {
  4294. limit = 10
  4295. }
  4296. if patientID <= 0 {
  4297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4298. return
  4299. }
  4300. timeLayout := "2006-01-02"
  4301. loc, _ := time.LoadLocation("Local")
  4302. var theStartTIme int64
  4303. if len(startTime) > 0 {
  4304. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4305. if err != nil {
  4306. theStartTIme = 0
  4307. }
  4308. theStartTIme = theTime.Unix()
  4309. }
  4310. var theEndtTIme int64
  4311. if len(endTime) > 0 {
  4312. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4313. if err != nil {
  4314. theEndtTIme = 0
  4315. }
  4316. theEndtTIme = theTime.Unix()
  4317. }
  4318. adminUserInfo := c.GetMobileAdminUserInfo()
  4319. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  4320. c.ServeSuccessJSON(map[string]interface{}{
  4321. "total": total,
  4322. "edus": edus,
  4323. })
  4324. return
  4325. }
  4326. func (c *PatientApiController) GetPatientSchedulesList() {
  4327. patientID, _ := c.GetInt64("patient_id", 0)
  4328. page, _ := c.GetInt64("page", 0)
  4329. limit, _ := c.GetInt64("limit", 0)
  4330. if patientID <= 0 {
  4331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4332. return
  4333. }
  4334. adminUserInfo := c.GetMobileAdminUserInfo()
  4335. todayTime := time.Now().Format("2006-01-02")
  4336. timeLayout := "2006-01-02 15:04:05"
  4337. loc, _ := time.LoadLocation("Local")
  4338. var theStartTime int64
  4339. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  4340. theStartTime = theTime.Unix()
  4341. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  4342. if len(schedules) > 0 {
  4343. for index, item := range schedules {
  4344. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  4345. schedules[index].Week = int64(week)
  4346. }
  4347. }
  4348. c.ServeSuccessJSON(map[string]interface{}{
  4349. "schedules": schedules,
  4350. })
  4351. return
  4352. }
  4353. func (c *PatientApiController) GetRecords() {
  4354. patientID, _ := c.GetInt64("patient_id", 0)
  4355. page, _ := c.GetInt64("page", 0)
  4356. limit, _ := c.GetInt64("limit", 0)
  4357. startTime := c.GetString("start_time", "")
  4358. endTime := c.GetString("end_time", "")
  4359. mode_id, _ := c.GetInt64("mode_id", 0)
  4360. if page <= 0 {
  4361. page = 1
  4362. }
  4363. if limit <= 0 {
  4364. limit = 10
  4365. }
  4366. if patientID <= 0 {
  4367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4368. return
  4369. }
  4370. timeLayout := "2006-01-02"
  4371. loc, _ := time.LoadLocation("Local")
  4372. var theStartTIme int64
  4373. if len(startTime) > 0 {
  4374. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4375. if err != nil {
  4376. theStartTIme = 0
  4377. }
  4378. theStartTIme = theTime.Unix()
  4379. }
  4380. var theEndtTIme int64
  4381. if len(endTime) > 0 {
  4382. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4383. if err != nil {
  4384. theEndtTIme = 0
  4385. }
  4386. theEndtTIme = theTime.Unix()
  4387. }
  4388. adminUserInfo := c.GetMobileAdminUserInfo()
  4389. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  4390. c.ServeSuccessJSON(map[string]interface{}{
  4391. "total": total,
  4392. "records": records,
  4393. })
  4394. return
  4395. }
  4396. func (c *PatientApiController) GetPatientMonitor() {
  4397. partition, _ := c.GetInt64("partition")
  4398. monitorDate := c.GetString("date")
  4399. patient_id, _ := c.GetInt64("patient_id")
  4400. timeLayout := "2006-01-02"
  4401. loc, _ := time.LoadLocation("Local")
  4402. var theStartTime int64
  4403. if len(monitorDate) > 0 {
  4404. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  4405. if err != nil {
  4406. theStartTime = 0
  4407. }
  4408. theStartTime = theTime.Unix()
  4409. }
  4410. adminInfo := c.GetMobileAdminUserInfo()
  4411. orgID := adminInfo.Org.Id
  4412. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  4413. if err != nil {
  4414. c.ErrorLog("获取排班信息失败:%v", err)
  4415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4416. } else {
  4417. if len(monitor) > 0 {
  4418. //获取所有床位
  4419. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  4420. //获取所有分区
  4421. zoneList, _ := service.GetAllZoneByList(orgID)
  4422. //获取透析处方
  4423. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  4424. //获取透前评估
  4425. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  4426. //获取上机
  4427. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  4428. //获取透后
  4429. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  4430. //获取透后监测
  4431. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  4432. //获取所有的患者
  4433. patients, _ := service.GetAllPatientListByListOne(orgID)
  4434. for _, it := range patients {
  4435. if orgID == 10445 {
  4436. if theStartTime <= 1703952000 {
  4437. listOne, _ := service.GetDialysisOrderCountTwentyEight(orgID, it.ID, theStartTime)
  4438. it.TotalDialysis = listOne.Count
  4439. }
  4440. if theStartTime >= 1704038400 {
  4441. listOrder, _ := service.GetDialysisOrderCountTenEight(it.ID, theStartTime)
  4442. it.TotalDialysis = listOrder.Count
  4443. }
  4444. }
  4445. }
  4446. //获取所有透析模式
  4447. treatments, _ := service.GetAllTreatModeByList(orgID)
  4448. for key, item := range monitor {
  4449. // 获取床位信息
  4450. for _, it := range numberList {
  4451. if item.BedId == it.ID {
  4452. monitor[key].DeviceNumber = it
  4453. break
  4454. }
  4455. }
  4456. //获取分区信息
  4457. for _, it := range zoneList {
  4458. if item.PartitionId == it.ID {
  4459. monitor[key].DeviceZone = it
  4460. }
  4461. }
  4462. for _, prescription := range prescriptions {
  4463. if item.PatientId == prescription.PatientId {
  4464. monitor[key].Prescription = prescription
  4465. break
  4466. }
  4467. }
  4468. // 透前评估
  4469. for _, assessmentBefore := range assessmentBefores {
  4470. if item.PatientId == assessmentBefore.PatientId {
  4471. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  4472. break
  4473. }
  4474. }
  4475. // 透析上下机
  4476. for _, dialysisOrder := range dialysisOrders {
  4477. if item.PatientId == dialysisOrder.PatientId {
  4478. monitor[key].DialysisOrder = dialysisOrder
  4479. break
  4480. }
  4481. }
  4482. // 治疗小节
  4483. for _, afterDislysis := range AssessmentAfterDislysis {
  4484. if item.PatientId == afterDislysis.PatientId {
  4485. monitor[key].AssessmentAfterDislysis = afterDislysis
  4486. break
  4487. }
  4488. }
  4489. for _, it := range monitorlist {
  4490. if item.PatientId == it.PatientId {
  4491. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  4492. }
  4493. }
  4494. for _, patient := range patients {
  4495. if item.PatientId == patient.ID {
  4496. monitor[key].MonitorPatients = patient
  4497. break
  4498. }
  4499. }
  4500. for _, treatment := range treatments {
  4501. if item.ModeId == treatment.ID {
  4502. monitor[key].TreatmentMode = treatment
  4503. break
  4504. }
  4505. }
  4506. }
  4507. }
  4508. }
  4509. //获取患者的透析次数
  4510. //count, err := service.GetDialysisCount(orgID, partition)
  4511. patients, err := service.GetAllpatientFourty(orgID)
  4512. if err == nil {
  4513. c.ServeSuccessJSON(map[string]interface{}{
  4514. "monitor": monitor,
  4515. //"patientCount": count,
  4516. "patients": patients,
  4517. })
  4518. } else {
  4519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4520. }
  4521. }
  4522. // /m/api/monitor/patient [get] 搜索病人的测量记录
  4523. // @param keyword:string 病人姓名或透析号
  4524. // @param page:int
  4525. func (this *PatientApiController) SearchMonitorPatient() {
  4526. keyword := this.GetString("keyword")
  4527. page, _ := this.GetInt("page")
  4528. if page <= 0 {
  4529. page = 1
  4530. }
  4531. if len(keyword) == 0 {
  4532. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4533. return
  4534. }
  4535. adminUserInfo := this.GetMobileAdminUserInfo()
  4536. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  4537. if getMonitorErr != nil {
  4538. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4539. return
  4540. } else {
  4541. this.ServeSuccessJSON(map[string]interface{}{
  4542. "monitor": monitors,
  4543. })
  4544. }
  4545. }
  4546. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  4547. id, _ := c.GetInt64("id", 0)
  4548. page, _ := c.GetInt64("page", 0)
  4549. limit, _ := c.GetInt64("limit", 0)
  4550. if id <= 0 {
  4551. c.ServeSuccessJSON(map[string]interface{}{
  4552. "solutions": nil,
  4553. })
  4554. return
  4555. }
  4556. if page <= 0 {
  4557. page = 1
  4558. }
  4559. if limit <= 0 {
  4560. limit = 10
  4561. }
  4562. adminInfo := c.GetMobileAdminUserInfo()
  4563. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  4564. c.ServeSuccessJSON(map[string]interface{}{
  4565. "solutions": solutions,
  4566. "total": total,
  4567. })
  4568. return
  4569. }
  4570. // GetDoctorAdvices 医嘱列表
  4571. func (c *PatientApiController) GetDoctorAdvices() {
  4572. id, _ := c.GetInt64("id", 0)
  4573. adviceType, _ := c.GetInt64("advice_type", 0)
  4574. stopType, _ := c.GetInt64("stop_state", 0)
  4575. startTime := c.GetString("start_time", "")
  4576. endTime := c.GetString("end_time", "")
  4577. keywords := c.GetString("keywords", "")
  4578. need, _ := c.GetInt64("need_doctor", 0)
  4579. adminUserInfo := c.GetMobileAdminUserInfo()
  4580. timeLayout := "2006-01-02"
  4581. loc, _ := time.LoadLocation("Local")
  4582. var theStartTIme int64
  4583. if len(startTime) > 0 {
  4584. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4585. if err != nil {
  4586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4587. return
  4588. }
  4589. theStartTIme = theTime.Unix()
  4590. }
  4591. var theEndtTIme int64
  4592. if len(endTime) > 0 {
  4593. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4594. if err != nil {
  4595. utils.ErrorLog(err.Error())
  4596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4597. return
  4598. }
  4599. theEndtTIme = theTime.Unix()
  4600. }
  4601. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  4602. if need == 1 {
  4603. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4604. c.ServeSuccessJSON(map[string]interface{}{
  4605. "advices": advices,
  4606. "total": total,
  4607. "users": users,
  4608. })
  4609. } else {
  4610. c.ServeSuccessJSON(map[string]interface{}{
  4611. "advices": advices,
  4612. "total": total,
  4613. "users": []string{},
  4614. })
  4615. }
  4616. return
  4617. }
  4618. func (c *PatientApiController) GetPrintDialysisOrder() {
  4619. xtno := c.GetString("xtno")
  4620. xtdate := c.GetString("xtdate")
  4621. timeLayout := "2006-01-02"
  4622. loc, _ := time.LoadLocation("Local")
  4623. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  4624. if err != nil {
  4625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4626. return
  4627. }
  4628. xttime := theTime.Unix()
  4629. //获取当前日期月份的第一天
  4630. firstmonth := service.GetFirstDateOfMonth(theTime)
  4631. firstMonthDate := firstmonth.Unix()
  4632. operatorIDs := make([]int64, 0)
  4633. adminUserInfo := c.GetMobileAdminUserInfo()
  4634. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4635. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  4636. //透析单
  4637. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4638. if dialysisOrder != nil {
  4639. if dialysisOrder.FinishNurse > 0 {
  4640. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  4641. }
  4642. if dialysisOrder.StartNurse > 0 {
  4643. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  4644. }
  4645. }
  4646. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4647. //透前评估
  4648. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4649. //透后评估
  4650. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4651. if AssessmentAfterDislysis.Modifier > 0 {
  4652. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  4653. }
  4654. //透析处方
  4655. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4656. if dialysisPrescription.PrescriptionDoctor > 0 {
  4657. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  4658. }
  4659. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4660. patientInfo.TotalDialysis = dialysis_count
  4661. //临时医嘱
  4662. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4663. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4664. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  4665. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  4666. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4667. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4668. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4669. for _, item := range projects {
  4670. cnt, _ := strconv.ParseFloat(item.Count, 64)
  4671. var advice models.HisDoctorAdviceInfo
  4672. advice.ID = item.ID
  4673. advice.Checker = item.Checker
  4674. advice.CheckTime = item.CheckTime
  4675. advice.CheckState = item.CheckState
  4676. advice.ExecutionState = item.ExecutionState
  4677. advice.ExecutionStaff = item.ExecutionStaff
  4678. //advice.PrescribingNumber = float64(item.Count)
  4679. advice.PrescribingNumber = cnt
  4680. advice.PrescribingNumberUnit = item.Unit
  4681. advice.AdviceDoctor = item.Doctor
  4682. if item.Type == 3 {
  4683. advice.AdviceName = item.GoodInfo.GoodName
  4684. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  4685. } else if item.Type == 2 {
  4686. advice.AdviceName = item.HisProject.ProjectName
  4687. }
  4688. advice.StartTime = item.StartTime
  4689. hisAdvice = append(hisAdvice, &advice)
  4690. }
  4691. }
  4692. if len(DoctorAdvice) > 0 {
  4693. for _, item := range DoctorAdvice {
  4694. if item.AdviceDoctor > 0 {
  4695. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  4696. }
  4697. if item.ExecutionStaff > 0 {
  4698. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  4699. }
  4700. if item.Checker > 0 {
  4701. operatorIDs = append(operatorIDs, item.Checker)
  4702. }
  4703. }
  4704. }
  4705. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4706. //透析监测
  4707. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4708. //透析小结
  4709. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4710. //接诊评估
  4711. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4712. //相关操作对应的操作人
  4713. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  4714. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  4715. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4716. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4717. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  4718. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4719. if config.IsOpen == 1 {
  4720. c.ServeSuccessJSON(map[string]interface{}{
  4721. "users": adminUser,
  4722. "patientInfo": patientInfo,
  4723. "PredialysisEvaluation": PredialysisEvaluation,
  4724. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4725. "dialysisPrescription": dialysisPrescription,
  4726. "advices": hisAdvice,
  4727. "monitors": Record,
  4728. "summary": TreatmentSummary,
  4729. "receiverTreatmentAccess": receiverTreatmentAccess,
  4730. "dialysisOrder": dialysisOrder,
  4731. "operators": operators,
  4732. "org_template_info": templateInfo,
  4733. "check": check,
  4734. "dialysiscount": dialysiscount,
  4735. "last_order": last_order,
  4736. "projects": projects,
  4737. "project_config": project_config,
  4738. "lastWeight": lastWeight,
  4739. "lastSchedule": lastSchedule,
  4740. "DoctorAdvice": DoctorAdvice,
  4741. "hisAdvice": hisAdvice,
  4742. })
  4743. }
  4744. if config.IsOpen == 0 || config.IsOpen == 2 {
  4745. c.ServeSuccessJSON(map[string]interface{}{
  4746. "users": adminUser,
  4747. "patientInfo": patientInfo,
  4748. "PredialysisEvaluation": PredialysisEvaluation,
  4749. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4750. "dialysisPrescription": dialysisPrescription,
  4751. "advices": DoctorAdvice,
  4752. "monitors": Record,
  4753. "summary": TreatmentSummary,
  4754. "receiverTreatmentAccess": receiverTreatmentAccess,
  4755. "dialysisOrder": dialysisOrder,
  4756. "operators": operators,
  4757. "org_template_info": templateInfo,
  4758. "check": check,
  4759. "dialysiscount": dialysiscount,
  4760. "last_order": last_order,
  4761. "projects": projects,
  4762. "project_config": project_config,
  4763. "lastWeight": lastWeight,
  4764. "lastSchedule": lastSchedule,
  4765. "DoctorAdvice": DoctorAdvice,
  4766. "hisAdvice": hisAdvice,
  4767. })
  4768. }
  4769. }
  4770. func (c *PatientApiController) CreateGroupAdvice() {
  4771. is_child, _ := c.GetInt64("is_child", 0)
  4772. if is_child == 1 {
  4773. patient, _ := c.GetInt64("id", 0)
  4774. if patient <= 0 {
  4775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4776. return
  4777. }
  4778. adminUserInfo := c.GetMobileAdminUserInfo()
  4779. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  4780. if patientInfo.ID == 0 {
  4781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4782. return
  4783. }
  4784. group_no, _ := c.GetInt64("group_no")
  4785. if group_no <= 0 {
  4786. group_no = 0
  4787. }
  4788. dataBody := make(map[string]interface{}, 0)
  4789. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4790. if err != nil {
  4791. utils.ErrorLog(err.Error())
  4792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4793. return
  4794. }
  4795. timeLayout := "2006-01-02"
  4796. loc, _ := time.LoadLocation("Local")
  4797. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4798. utils.ErrorLog("advice_type")
  4799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4800. return
  4801. }
  4802. adviceType := int64(dataBody["advice_type"].(float64))
  4803. if adviceType != 1 && adviceType != 2 {
  4804. utils.ErrorLog("advice_type != 1&&2")
  4805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4806. return
  4807. }
  4808. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4809. utils.ErrorLog("start_time")
  4810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4811. return
  4812. }
  4813. startTime2, _ := dataBody["start_time"].(string)
  4814. time_arr := strings.Split(startTime2, " ")
  4815. if len(time_arr) > 0 {
  4816. startTime2 = time_arr[0]
  4817. }
  4818. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4819. utils.ErrorLog("advice_date")
  4820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4821. return
  4822. }
  4823. advice_date, _ := dataBody["advice_date"].(string)
  4824. var advicedateunix int64
  4825. if len(advice_date) > 0 {
  4826. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  4827. if err != nil {
  4828. fmt.Println(err)
  4829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4830. return
  4831. }
  4832. advicedateunix = theTime.Unix()
  4833. }
  4834. adviceDate := startTime2
  4835. if len(adviceDate) == 0 {
  4836. utils.ErrorLog("len(adviceDate) == 0")
  4837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4838. return
  4839. }
  4840. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4841. if err != nil {
  4842. utils.ErrorLog(err.Error())
  4843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4844. return
  4845. }
  4846. AdviceDate := advicedateunix
  4847. RecordDate := advicedateunix
  4848. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4849. utils.ErrorLog("start_time")
  4850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4851. return
  4852. }
  4853. startTime, _ := dataBody["start_time"].(string)
  4854. if len(startTime) == 0 {
  4855. utils.ErrorLog("len(start_time) == 0")
  4856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4857. return
  4858. }
  4859. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  4860. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  4861. if err != nil {
  4862. utils.ErrorLog(err.Error())
  4863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4864. return
  4865. }
  4866. StartTime := theTime.Unix()
  4867. Remark := ""
  4868. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4869. remark, _ := dataBody["remark"].(string)
  4870. Remark = remark
  4871. }
  4872. Startdate := int64(dataBody["record_date"].(float64))
  4873. var advices []*models.GroupAdvice
  4874. // utils.TraceLog("%+v", dataBody["adviceNames"])
  4875. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  4876. utils.ErrorLog("adviceNames")
  4877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4878. return
  4879. }
  4880. adviceNames := dataBody["adviceNames"].([]interface{})
  4881. for _, adviceNameMap := range adviceNames {
  4882. adviceNameM := adviceNameMap.(map[string]interface{})
  4883. var advice models.GroupAdvice
  4884. advice.Remark = Remark
  4885. advice.AdviceType = adviceType
  4886. advice.StartTime = StartTime
  4887. if adminUserInfo.Org.Id == 10340 {
  4888. advice.AdviceDate = AdviceDate
  4889. advice.RecordDate = RecordDate
  4890. }
  4891. if adminUserInfo.Org.Id != 10340 {
  4892. advice.AdviceDate = theTimeOne.Unix()
  4893. advice.RecordDate = theTimeOne.Unix()
  4894. }
  4895. advice.Status = 1
  4896. advice.CreatedTime = time.Now().Unix()
  4897. advice.UpdatedTime = time.Now().Unix()
  4898. advice.StopState = 2
  4899. advice.ExecutionState = 2
  4900. advice.UserOrgId = adminUserInfo.Org.Id
  4901. advice.PatientId = patientInfo.ID
  4902. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4903. advice.IsSettle = 2
  4904. //入口
  4905. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  4906. if errcode > 0 {
  4907. c.ServeFailJSONWithSGJErrorCode(errcode)
  4908. return
  4909. }
  4910. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  4911. subdrugs := adviceNameM["subdrugs"].([]interface{})
  4912. if len(subdrugs) > 0 {
  4913. for _, subdrug := range subdrugs {
  4914. var s models.GroupAdvice
  4915. s.Remark = Remark
  4916. s.AdviceType = adviceType
  4917. s.StartTime = StartTime
  4918. s.AdviceDate = AdviceDate
  4919. s.RecordDate = RecordDate
  4920. s.Status = 1
  4921. s.CreatedTime = time.Now().Unix()
  4922. s.UpdatedTime = time.Now().Unix()
  4923. s.StopState = 2
  4924. s.ExecutionState = 2
  4925. s.UserOrgId = adminUserInfo.Org.Id
  4926. s.PatientId = patientInfo.ID
  4927. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  4928. s.IsSettle = 2
  4929. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  4930. if errcode > 0 {
  4931. c.ServeFailJSONWithSGJErrorCode(errcode)
  4932. return
  4933. }
  4934. advice.Children = append(advice.Children, &s)
  4935. }
  4936. }
  4937. }
  4938. //长沙南雅
  4939. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  4940. //查询该患者今日有没有双人核对
  4941. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  4942. if check.ID > 0 {
  4943. advice.Checker = check.Modifier
  4944. advice.CheckState = 1
  4945. advice.CheckTime = time.Now().Unix()
  4946. }
  4947. }
  4948. advices = append(advices, &advice)
  4949. }
  4950. // 查询信息规挡的设置天数
  4951. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4952. if infor.ID > 0 && infor.WeekDay > 0 {
  4953. var cha_time int64
  4954. timeNowStr := time.Now().Format("2006-01-02")
  4955. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4956. //今日的日期减去设置的日期
  4957. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4958. if cha_time >= Startdate {
  4959. //查询审核是否允许
  4960. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id, 5)
  4961. //申请状态不允许的情况 拒绝修改
  4962. if infor.ApplicationStatus != 1 {
  4963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4964. return
  4965. }
  4966. }
  4967. }
  4968. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  4969. for _, item := range advices {
  4970. //记录日志
  4971. byterequest, _ := json.Marshal(item)
  4972. adviceLog := models.XtDoctorAdviceLog{
  4973. UserOrgId: item.UserOrgId,
  4974. PatientId: item.PatientId,
  4975. AdminUserId: adminUserInfo.AdminUser.Id,
  4976. Module: 1,
  4977. ErrLog: string(byterequest),
  4978. Status: 1,
  4979. Ctime: time.Now().Unix(),
  4980. Mtime: 0,
  4981. Source: "手机端新增医嘱",
  4982. RecordDate: item.AdviceDate,
  4983. }
  4984. service.CreateDoctorAdviceLog(adviceLog)
  4985. }
  4986. finish := models.XtDialysisFinish{
  4987. IsFinish: 1,
  4988. UserOrgId: adminUserInfo.Org.Id,
  4989. Status: 1,
  4990. Ctime: time.Now().Unix(),
  4991. Mtime: 0,
  4992. Module: 4,
  4993. RecordDate: advicedateunix,
  4994. Sourse: 1,
  4995. PatientId: patient,
  4996. }
  4997. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4, patient)
  4998. if dialysisFinish.ID == 0 {
  4999. service.CreateDialysisFinish(finish)
  5000. }
  5001. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  5002. redis := service.RedisClient()
  5003. //清空key 值
  5004. redis.Set(key, "", time.Second)
  5005. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5006. redis.Set(keyOne, "", time.Second)
  5007. defer redis.Close()
  5008. if createErr != nil {
  5009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5010. return
  5011. }
  5012. c.ServeSuccessJSON(map[string]interface{}{
  5013. "msg": "ok",
  5014. "advices": newAdvices,
  5015. })
  5016. return
  5017. } else if is_child == 2 {
  5018. patient, _ := c.GetInt64("id", 0)
  5019. if patient <= 0 {
  5020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5021. return
  5022. }
  5023. adminUserInfo := c.GetMobileAdminUserInfo()
  5024. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  5025. if patientInfo.ID == 0 {
  5026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5027. return
  5028. }
  5029. var advice models.DoctorAdvice
  5030. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  5031. if code > 0 {
  5032. c.ServeFailJSONWithSGJErrorCode(code)
  5033. return
  5034. }
  5035. if advice.ParentId > 0 {
  5036. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  5037. if old.ID == 0 || old.PatientId != patient {
  5038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  5039. return
  5040. }
  5041. if old.StopState == 1 || old.ExecutionState == 1 {
  5042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  5043. return
  5044. }
  5045. if old.ParentId > 0 {
  5046. advice.ParentId = old.ParentId
  5047. }
  5048. advice.StartTime = old.StartTime
  5049. advice.AdviceDoctor = old.AdviceDoctor
  5050. advice.DeliveryWay = old.DeliveryWay
  5051. advice.ExecutionFrequency = old.ExecutionFrequency
  5052. advice.GroupNo = old.GroupNo
  5053. }
  5054. advice.Status = 1
  5055. advice.CreatedTime = time.Now().Unix()
  5056. advice.UpdatedTime = time.Now().Unix()
  5057. advice.StopState = 2
  5058. advice.ExecutionState = 2
  5059. advice.UserOrgId = adminUserInfo.Org.Id
  5060. advice.PatientId = patient
  5061. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5062. advice.IsSettle = 2
  5063. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  5064. if advice.PrescribingNumber == 0 {
  5065. advice.PrescribingNumber = 1
  5066. }
  5067. //查询该患者今日有没有双人核对
  5068. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  5069. if check.ID > 0 {
  5070. advice.Checker = check.Modifier
  5071. advice.CheckState = 1
  5072. advice.CheckTime = time.Now().Unix()
  5073. }
  5074. }
  5075. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5076. if infor.ID > 0 {
  5077. var cha_time int64
  5078. timeNowStr := time.Now().Format("2006-01-02")
  5079. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5080. //今日的日期减去设置的日期
  5081. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5082. if cha_time >= advice.RecordDate {
  5083. //查询审核是否允许
  5084. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id, 4)
  5085. //申请状态不允许的情况 拒绝修改
  5086. if infor.ApplicationStatus != 1 {
  5087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5088. return
  5089. }
  5090. }
  5091. }
  5092. err := service.CreateDoctorAdvice(&advice)
  5093. //记录日志
  5094. byterequest, _ := json.Marshal(advice)
  5095. adviceLog := models.XtDoctorAdviceLog{
  5096. UserOrgId: advice.UserOrgId,
  5097. PatientId: advice.PatientId,
  5098. AdminUserId: adminUserInfo.Org.Id,
  5099. Module: 1,
  5100. ErrLog: string(byterequest),
  5101. Status: 1,
  5102. Ctime: time.Now().Unix(),
  5103. Mtime: 0,
  5104. Source: "手机端新增医嘱",
  5105. RecordDate: advice.AdviceDate,
  5106. }
  5107. service.CreateDoctorAdviceLog(adviceLog)
  5108. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5109. redis := service.RedisClient()
  5110. //清空key 值
  5111. redis.Set(key, "", time.Second)
  5112. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5113. redis.Set(keyOne, "", time.Second)
  5114. defer redis.Close()
  5115. if err != nil {
  5116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5117. return
  5118. }
  5119. c.ServeSuccessJSON(map[string]interface{}{
  5120. "msg": "ok",
  5121. "advice": advice,
  5122. })
  5123. return
  5124. }
  5125. }
  5126. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  5127. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  5128. utils.ErrorLog("advice_name")
  5129. return enums.ErrorCodeParamWrong
  5130. }
  5131. adviceName, _ := json["advice_name"].(string)
  5132. if len(adviceName) == 0 {
  5133. utils.ErrorLog("len(advice_name) == 0")
  5134. return enums.ErrorCodeParamWrong
  5135. }
  5136. advice.AdviceName = adviceName
  5137. adviceDesc, _ := json["advice_desc"].(string)
  5138. advice.AdviceDesc = adviceDesc
  5139. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5140. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5141. advice.DrugSpec = drugSpec
  5142. }
  5143. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5144. remark, _ := json["remark"].(string)
  5145. advice.Remark = remark
  5146. }
  5147. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  5148. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  5149. // advice.Way = src_type
  5150. //}
  5151. if json["way"] == nil {
  5152. advice.Way = 0
  5153. } else {
  5154. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  5155. way := int64(json["way"].(float64))
  5156. advice.Way = way
  5157. }
  5158. }
  5159. if json["drug_id"] == nil {
  5160. advice.DrugId = 0
  5161. } else {
  5162. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  5163. drug_id := int64(json["drug_id"].(float64))
  5164. advice.DrugId = drug_id
  5165. }
  5166. }
  5167. if json["drug_name_id"] == nil {
  5168. advice.DrugNameId = 0
  5169. } else {
  5170. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  5171. drug_name_id := int64(json["drug_name_id"].(float64))
  5172. advice.DrugNameId = drug_name_id
  5173. }
  5174. }
  5175. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  5176. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  5177. advice.DrugSpecUnit = drugSpecUnit
  5178. }
  5179. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5180. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5181. advice.SingleDose = singleDose
  5182. }
  5183. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5184. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5185. advice.SingleDoseUnit = singleDoseUnit
  5186. }
  5187. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5188. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5189. advice.PrescribingNumber = prescribingNumber
  5190. }
  5191. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5192. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5193. advice.PrescribingNumberUnit = prescribingNumberUnit
  5194. }
  5195. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5196. deliveryWay, _ := json["delivery_way"].(string)
  5197. advice.DeliveryWay = deliveryWay
  5198. }
  5199. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5200. executionFrequency, _ := json["execution_frequency"].(string)
  5201. advice.ExecutionFrequency = executionFrequency
  5202. }
  5203. return 0
  5204. }
  5205. func (c *PatientApiController) DelDoctorAdvice() {
  5206. groupno, _ := c.GetInt64("groupno", -1)
  5207. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  5208. patient_id, _ := c.GetInt64("patient_id")
  5209. doc_advice_date, _ := c.GetInt64("advice_date")
  5210. redis := service.RedisClient()
  5211. if is_sub == 1 { //是
  5212. advice_id, _ := c.GetInt64("advice_id")
  5213. adminUserInfo := c.GetMobileAdminUserInfo()
  5214. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  5215. if advice.ID == 0 {
  5216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5217. return
  5218. }
  5219. advice.Status = 0
  5220. advice.UpdatedTime = time.Now().Unix()
  5221. advice.Modifier = adminUserInfo.AdminUser.Id
  5222. // 查询信息规挡的设置天数
  5223. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5224. if infor.ID > 0 && infor.WeekDay > 0 {
  5225. var cha_time int64
  5226. timeNowStr := time.Now().Format("2006-01-02")
  5227. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5228. //今日的日期减去设置的日期
  5229. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5230. if cha_time >= advice.AdviceDate {
  5231. //查询审核是否允许
  5232. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5233. //申请状态不允许的情况 拒绝修改
  5234. if infor.ApplicationStatus != 1 {
  5235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5236. return
  5237. }
  5238. }
  5239. }
  5240. //自备药
  5241. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5242. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5243. //查询库存是否是自备药
  5244. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  5245. if selfBasedrug.IsSelfDrug == 1 {
  5246. creater := adminUserInfo.AdminUser.Id
  5247. //退库
  5248. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  5249. }
  5250. }
  5251. err := service.DeleteDoctorAdvice(&advice)
  5252. //记录日志
  5253. byterequest, _ := json.Marshal(advice)
  5254. adviceLog := models.XtDoctorAdviceLog{
  5255. UserOrgId: advice.UserOrgId,
  5256. PatientId: advice.PatientId,
  5257. AdminUserId: adminUserInfo.AdminUser.Id,
  5258. Module: 4,
  5259. ErrLog: string(byterequest),
  5260. Status: 1,
  5261. Ctime: time.Now().Unix(),
  5262. Mtime: 0,
  5263. Source: "手机端删除医嘱",
  5264. RecordDate: advice.RecordDate,
  5265. }
  5266. service.CreateDoctorAdviceLog(adviceLog)
  5267. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5268. redis.Set(key, "", time.Second)
  5269. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5270. redis.Set(keyTwo, "", time.Second)
  5271. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5272. redis.Set(keyThree, "", time.Second)
  5273. redis.Close()
  5274. if err != nil {
  5275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5276. return
  5277. }
  5278. c.ServeSuccessJSON(map[string]interface{}{
  5279. "msg": "ok",
  5280. })
  5281. return
  5282. } else { //
  5283. var ids []string
  5284. if groupno == 0 {
  5285. advice_id := c.GetString("advice_id")
  5286. ids = strings.Split(advice_id, ",")
  5287. if len(ids) <= 0 {
  5288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5289. return
  5290. }
  5291. }
  5292. if groupno < 0 {
  5293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5294. return
  5295. }
  5296. adminUserInfo := c.GetMobileAdminUserInfo()
  5297. var advice models.DoctorAdvice
  5298. if groupno > 0 {
  5299. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  5300. if advice.ID == 0 {
  5301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5302. return
  5303. }
  5304. } else {
  5305. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  5306. for _, item := range advices {
  5307. if item.ID == 0 {
  5308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5309. return
  5310. }
  5311. }
  5312. }
  5313. advice.UpdatedTime = time.Now().Unix()
  5314. advice.Status = 0
  5315. advice.GroupNo = groupno
  5316. advice.Modifier = adminUserInfo.AdminUser.Id
  5317. var err error
  5318. if groupno > 0 {
  5319. // 查询信息规挡的设置天数
  5320. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5321. if infor.ID > 0 {
  5322. var cha_time int64
  5323. timeNowStr := time.Now().Format("2006-01-02")
  5324. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5325. //今日的日期减去设置的日期
  5326. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5327. if cha_time >= advice.AdviceDate {
  5328. //查询审核是否允许
  5329. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5330. //申请状态不允许的情况 拒绝修改
  5331. if infor.ApplicationStatus != 1 {
  5332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5333. return
  5334. }
  5335. }
  5336. }
  5337. //自备药
  5338. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5339. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5340. //查询库存是否是自备药
  5341. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  5342. if selfBasedrug.IsSelfDrug == 1 {
  5343. creater := adminUserInfo.AdminUser.Id
  5344. //退库
  5345. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  5346. }
  5347. }
  5348. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  5349. //记录日志
  5350. byterequest, _ := json.Marshal(advice)
  5351. adviceLog := models.XtDoctorAdviceLog{
  5352. UserOrgId: advice.UserOrgId,
  5353. PatientId: advice.PatientId,
  5354. AdminUserId: adminUserInfo.AdminUser.Id,
  5355. Module: 4,
  5356. ErrLog: string(byterequest),
  5357. Status: 1,
  5358. Ctime: time.Now().Unix(),
  5359. Mtime: 0,
  5360. Source: "手机端删除医嘱",
  5361. RecordDate: advice.RecordDate,
  5362. }
  5363. service.CreateDoctorAdviceLog(adviceLog)
  5364. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5365. redis.Set(key, "", time.Second)
  5366. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5367. redis.Set(keyTwo, "", time.Second)
  5368. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5369. redis.Set(keyThree, "", time.Second)
  5370. } else {
  5371. // 查询信息规挡的设置天数
  5372. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5373. if infor.ID > 0 {
  5374. var cha_time int64
  5375. timeNowStr := time.Now().Format("2006-01-02")
  5376. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5377. //今日的日期减去设置的日期
  5378. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5379. if cha_time >= advice.AdviceDate {
  5380. //查询审核是否允许
  5381. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5382. //申请状态不允许的情况 拒绝修改
  5383. if infor.ApplicationStatus != 1 {
  5384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5385. return
  5386. }
  5387. }
  5388. }
  5389. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  5390. advicelist, _ := service.GetBatchDoctorAdviceList(ids, adminUserInfo.Org.Id)
  5391. for _, item := range advicelist {
  5392. //自备药
  5393. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5394. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5395. //查询库存是否是自备药
  5396. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(item.DrugId, item.UserOrgId)
  5397. if selfBasedrug.IsSelfDrug == 1 {
  5398. creater := adminUserInfo.AdminUser.Id
  5399. //退库
  5400. service.SelfDrugAutoAddCancelInfoOne(item, creater)
  5401. }
  5402. }
  5403. //记录日志
  5404. byterequest, _ := json.Marshal(item)
  5405. adviceLog := models.XtDoctorAdviceLog{
  5406. UserOrgId: item.UserOrgId,
  5407. PatientId: item.PatientId,
  5408. AdminUserId: adminUserInfo.AdminUser.Id,
  5409. Module: 4,
  5410. ErrLog: string(byterequest),
  5411. Status: 1,
  5412. Ctime: time.Now().Unix(),
  5413. Mtime: 0,
  5414. Source: "手机端批量删除医嘱",
  5415. RecordDate: item.RecordDate,
  5416. }
  5417. service.CreateDoctorAdviceLog(adviceLog)
  5418. }
  5419. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5420. redis.Set(key, "", time.Second)
  5421. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5422. redis.Set(keyTwo, "", time.Second)
  5423. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5424. redis.Set(keyThree, "", time.Second)
  5425. redis.Close()
  5426. }
  5427. if err != nil {
  5428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5429. return
  5430. }
  5431. c.ServeSuccessJSON(map[string]interface{}{
  5432. "msg": "ok",
  5433. })
  5434. return
  5435. }
  5436. }
  5437. // /m/api/advice/group/modify_starttime [post]
  5438. // @param group_no:int
  5439. // @param start_time:string yyyy-MM-dd hh:mm:ss
  5440. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  5441. group_no, _ := this.GetInt64("group_no")
  5442. start_time_str := this.GetString("start_time")
  5443. if group_no <= 0 || len(start_time_str) == 0 {
  5444. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5445. return
  5446. }
  5447. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  5448. if parseTimeErr != nil {
  5449. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  5450. return
  5451. }
  5452. adminUserInfo := this.GetMobileAdminUserInfo()
  5453. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  5454. if updateStartTimeErr != nil {
  5455. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  5456. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5457. return
  5458. }
  5459. this.ServeSuccessJSON(map[string]interface{}{
  5460. "start_time": startTime.Unix(),
  5461. })
  5462. }
  5463. func (this *PatientApiController) DelSubDoctorAdvice() {
  5464. advice_id, _ := this.GetInt64("advice_id")
  5465. adminUserInfo := this.GetMobileAdminUserInfo()
  5466. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  5467. if advice.ID == 0 {
  5468. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5469. return
  5470. }
  5471. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  5472. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  5473. // return
  5474. //}
  5475. advice.Status = 0
  5476. advice.UpdatedTime = time.Now().Unix()
  5477. advice.Modifier = adminUserInfo.AdminUser.Id
  5478. err := service.DeleteDoctorAdvice(&advice)
  5479. if err != nil {
  5480. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5481. return
  5482. }
  5483. this.ServeSuccessJSON(map[string]interface{}{
  5484. "msg": "ok",
  5485. })
  5486. return
  5487. }
  5488. func (this *PatientApiController) GetAdviceUnReadMessage() {
  5489. //adminUserInfo := this.GetMobileAdminUserInfo()
  5490. //service.FindUnReadDoctorAdviceMessage()
  5491. }
  5492. func (this *PatientApiController) GetPatientsByKeyWord() {
  5493. keyWord := this.GetString("keyword")
  5494. adminUserInfo := this.GetMobileAdminUserInfo()
  5495. today := utils.ZeroHourTimeOfDay(time.Now())
  5496. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  5497. if err != nil {
  5498. utils.ErrorLog(err.Error())
  5499. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5500. return
  5501. }
  5502. this.ServeSuccessJSON(map[string]interface{}{
  5503. "patient": patient,
  5504. })
  5505. }
  5506. func (this *PatientApiController) GetSearchPatient() {
  5507. keyWord := this.GetString("keyword")
  5508. adminUserInfo := this.GetMobileAdminUserInfo()
  5509. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  5510. if err != nil {
  5511. utils.ErrorLog(err.Error())
  5512. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5513. return
  5514. }
  5515. this.ServeSuccessJSON(map[string]interface{}{
  5516. "patient": patient,
  5517. })
  5518. }
  5519. func (c *PatientApiController) ExecProject() {
  5520. execution_time := c.GetString("execution_time")
  5521. project_id, _ := c.GetInt64("project_id")
  5522. team_id, _ := c.GetInt64("team_id")
  5523. is_check_team, _ := c.GetInt64("is_check_team")
  5524. if len(execution_time) <= 0 {
  5525. utils.ErrorLog("execution_time")
  5526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5527. return
  5528. }
  5529. timeLayout2 := "2006-01-02 15:04:05"
  5530. loc, _ := time.LoadLocation("Local")
  5531. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  5532. if errs != nil {
  5533. utils.ErrorLog(errs.Error())
  5534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5535. return
  5536. }
  5537. adminInfo := c.GetMobileAdminUserInfo()
  5538. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5539. if project.Type == 3 {
  5540. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  5541. if good.IsUser != 1 {
  5542. //查询开关是否开启
  5543. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  5544. //开关已经开启
  5545. if stockSetting.IsType == 1 {
  5546. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  5547. scheduleDateStart := theTime.Format("2006-01-02")
  5548. timeLayout3 := "2006-01-02"
  5549. loc, _ := time.LoadLocation("Local")
  5550. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  5551. //查询该耗材是否已经出库
  5552. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  5553. if auto.ID == 0 {
  5554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  5555. return
  5556. }
  5557. }
  5558. }
  5559. if good.IsUser == 1 && good.IsWarehouse == 1 {
  5560. //查询开关是否开启
  5561. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  5562. //开关已经开启
  5563. if stockSetting.IsType == 1 {
  5564. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  5565. scheduleDateStart := theTime.Format("2006-01-02")
  5566. timeLayout3 := "2006-01-02"
  5567. loc, _ := time.LoadLocation("Local")
  5568. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  5569. //查询该耗材是否已经出库
  5570. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  5571. if auto.ID == 0 {
  5572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  5573. return
  5574. }
  5575. }
  5576. }
  5577. }
  5578. if project.ExecutionState == 1 {
  5579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  5580. return
  5581. }
  5582. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  5583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5584. return
  5585. }
  5586. project.ExecutionState = 1
  5587. project.ExecutionStaff = adminInfo.AdminUser.Id
  5588. project.ExecutionTime = theTime.Unix()
  5589. if team_id == 0 {
  5590. // 查询信息规挡的设置天数
  5591. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5592. if infor.ID > 0 {
  5593. var cha_time int64
  5594. timeNowStr := time.Now().Format("2006-01-02")
  5595. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5596. //今日的日期减去设置的日期
  5597. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5598. if cha_time >= project.RecordDate {
  5599. //查询审核是否允许
  5600. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5601. //申请状态不允许的情况 拒绝修改
  5602. if infor.ApplicationStatus != 1 {
  5603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5604. return
  5605. }
  5606. }
  5607. }
  5608. err := service.SaveHisProject(&project)
  5609. if err == nil {
  5610. c.ServeSuccessJSON(map[string]interface{}{
  5611. "project": project,
  5612. })
  5613. } else {
  5614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5615. return
  5616. }
  5617. } else {
  5618. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5619. // 查询信息规挡的设置天数
  5620. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5621. if infor.ID > 0 {
  5622. var cha_time int64
  5623. timeNowStr := time.Now().Format("2006-01-02")
  5624. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5625. //今日的日期减去设置的日期
  5626. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5627. if cha_time >= project.RecordDate {
  5628. //查询审核是否允许
  5629. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5630. //申请状态不允许的情况 拒绝修改
  5631. if infor.ApplicationStatus != 1 {
  5632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5633. return
  5634. }
  5635. }
  5636. }
  5637. err := service.SaveHisProject(&project)
  5638. if err == nil {
  5639. c.ServeSuccessJSON(map[string]interface{}{
  5640. "project": project,
  5641. })
  5642. } else {
  5643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5644. return
  5645. }
  5646. } else {
  5647. // 查询信息规挡的设置天数
  5648. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5649. if infor.ID > 0 {
  5650. var cha_time int64
  5651. timeNowStr := time.Now().Format("2006-01-02")
  5652. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5653. //今日的日期减去设置的日期
  5654. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5655. if cha_time >= project.RecordDate {
  5656. //查询审核是否允许
  5657. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5658. //申请状态不允许的情况 拒绝修改
  5659. if infor.ApplicationStatus != 1 {
  5660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5661. return
  5662. }
  5663. }
  5664. }
  5665. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5666. var ids []int64
  5667. for _, items := range ps {
  5668. ids = append(ids, items.ID)
  5669. }
  5670. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  5671. if err == nil {
  5672. c.ServeSuccessJSON(map[string]interface{}{
  5673. "project": project,
  5674. })
  5675. } else {
  5676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5677. return
  5678. }
  5679. }
  5680. }
  5681. }
  5682. func (c *PatientApiController) CheckProject() {
  5683. adminInfo := c.GetMobileAdminUserInfo()
  5684. project_id, _ := c.GetInt64("project_id")
  5685. team_id, _ := c.GetInt64("team_id")
  5686. is_check_team, _ := c.GetInt64("is_check_team")
  5687. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5688. if project.CheckState == 1 {
  5689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  5690. return
  5691. }
  5692. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  5693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5694. return
  5695. }
  5696. project.Checker = adminInfo.AdminUser.Id
  5697. project.CheckTime = time.Now().Unix()
  5698. project.CheckState = 1
  5699. if team_id == 0 {
  5700. // 查询信息规挡的设置天数
  5701. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5702. if infor.ID > 0 {
  5703. var cha_time int64
  5704. timeNowStr := time.Now().Format("2006-01-02")
  5705. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5706. //今日的日期减去设置的日期
  5707. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5708. if cha_time >= project.RecordDate {
  5709. //查询审核是否允许
  5710. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5711. //申请状态不允许的情况 拒绝修改
  5712. if infor.ApplicationStatus != 1 {
  5713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5714. return
  5715. }
  5716. }
  5717. }
  5718. err := service.SaveHisProject(&project)
  5719. if err == nil {
  5720. c.ServeSuccessJSON(map[string]interface{}{
  5721. "msg": "ok",
  5722. "project": project,
  5723. })
  5724. } else {
  5725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5726. return
  5727. }
  5728. } else {
  5729. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5730. // 查询信息规挡的设置天数
  5731. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5732. if infor.ID > 0 {
  5733. var cha_time int64
  5734. timeNowStr := time.Now().Format("2006-01-02")
  5735. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5736. //今日的日期减去设置的日期
  5737. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5738. if cha_time >= project.RecordDate {
  5739. //查询审核是否允许
  5740. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5741. //申请状态不允许的情况 拒绝修改
  5742. if infor.ApplicationStatus != 1 {
  5743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5744. return
  5745. }
  5746. }
  5747. }
  5748. err := service.SaveHisProject(&project)
  5749. if err == nil {
  5750. c.ServeSuccessJSON(map[string]interface{}{
  5751. "msg": "ok",
  5752. "project": project,
  5753. })
  5754. } else {
  5755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5756. return
  5757. }
  5758. } else {
  5759. // 查询信息规挡的设置天数
  5760. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5761. if infor.ID > 0 {
  5762. var cha_time int64
  5763. timeNowStr := time.Now().Format("2006-01-02")
  5764. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5765. //今日的日期减去设置的日期
  5766. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5767. if cha_time >= project.RecordDate {
  5768. //查询审核是否允许
  5769. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5770. //申请状态不允许的情况 拒绝修改
  5771. if infor.ApplicationStatus != 1 {
  5772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5773. return
  5774. }
  5775. }
  5776. }
  5777. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5778. var ids []int64
  5779. for _, items := range ps {
  5780. ids = append(ids, items.ID)
  5781. }
  5782. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  5783. if err == nil {
  5784. c.ServeSuccessJSON(map[string]interface{}{
  5785. "project": project,
  5786. })
  5787. } else {
  5788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5789. return
  5790. }
  5791. }
  5792. }
  5793. }