patient_api_controller.go 239KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769
  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 == 10644 {
  1940. newadviceInfo := &models.HisDoctorAdviceInfo{
  1941. ID: advice.ID,
  1942. UserOrgId: advice.UserOrgId,
  1943. PatientId: advice.PatientId,
  1944. HisPatientId: advice.HisPatientId,
  1945. AdviceType: advice.AdviceType,
  1946. AdviceDate: advice.AdviceDate,
  1947. StartTime: advice.StartTime,
  1948. AdviceName: advice.AdviceName,
  1949. AdviceDesc: advice.AdviceDesc,
  1950. ReminderDate: advice.ReminderDate,
  1951. SingleDose: advice.SingleDose,
  1952. SingleDoseUnit: advice.SingleDoseUnit,
  1953. PrescribingNumber: advice.PrescribingNumber,
  1954. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1955. DeliveryWay: advice.DeliveryWay,
  1956. ExecutionFrequency: advice.ExecutionFrequency,
  1957. AdviceDoctor: advice.AdviceDoctor,
  1958. Status: advice.Status,
  1959. CreatedTime: advice.CreatedTime,
  1960. UpdatedTime: advice.UpdatedTime,
  1961. AdviceAffirm: advice.AdviceAffirm,
  1962. Remark: advice.Remark,
  1963. StopTime: advice.StopTime,
  1964. StopReason: advice.StopReason,
  1965. StopDoctor: advice.StopDoctor,
  1966. StopState: advice.StopState,
  1967. ParentId: advice.ParentId,
  1968. ExecutionTime: advice.ExecutionTime,
  1969. ExecutionStaff: advice.ExecutionStaff,
  1970. ExecutionState: advice.ExecutionState,
  1971. Checker: advice.Checker,
  1972. RecordDate: advice.RecordDate,
  1973. DialysisOrderId: advice.DialysisOrderId,
  1974. CheckTime: advice.CheckTime,
  1975. CheckState: advice.CheckState,
  1976. DrugSpec: advice.DrugSpec,
  1977. DrugSpecUnit: advice.DrugSpecUnit,
  1978. Groupno: advice.Groupno,
  1979. RemindType: advice.RemindType,
  1980. FrequencyType: advice.FrequencyType,
  1981. DayCount: advice.DayCount,
  1982. WeekDay: advice.WeekDay,
  1983. TemplateId: advice.TemplateId,
  1984. Modifier: advice.Modifier,
  1985. DrugId: advice.DrugId,
  1986. Price: advice.Price,
  1987. PrescriptionId: advice.PrescriptionId,
  1988. MedListCodg: advice.MedListCodg,
  1989. FeedetlSn: advice.FeedetlSn,
  1990. Day: advice.DayCount,
  1991. ChildDoctorAdvice: nil,
  1992. Drug: models.Drug{},
  1993. Diagnosis: advice.Diagnosis,
  1994. Way: advice.Way,
  1995. HospApprFlag: advice.HospApprFlag,
  1996. LmtUsedFlag: advice.LmtUsedFlag,
  1997. HisOrderInfo: models.HisOrderInfo{},
  1998. IsMedicine: advice.IsMedicine,
  1999. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  2000. Child: nil,
  2001. IsSettle: advice.IsSettle,
  2002. IsMobile: advice.IsMobile,
  2003. IsSelfDrug: advice.IsSelfDrug,
  2004. DrugWayCount: advice.DrugWayCount,
  2005. }
  2006. outListExport, _ := service.GetWarehouseOutListExport(advice.DrugId, advice.PatientId, advice.AdviceDate, advice.ID)
  2007. fmt.Println(outListExport)
  2008. //var out_count int64
  2009. //if len(outListExport) > 0 {
  2010. // for _, item := range outListExport {
  2011. // if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2012. // out_count = item.Count * medical.MinNumber
  2013. // }
  2014. // if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2015. // out_count = item.Count
  2016. // }
  2017. // if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2018. // out_count = item.Count * medical.MinNumber
  2019. // }
  2020. //
  2021. // }
  2022. //}
  2023. //按最小单位出库
  2024. //var cha_count = total_count - out_count
  2025. var cha_count = 100
  2026. fmt.Println("cha_count--------------------------------------", cha_count)
  2027. newadviceInfo.PrescribingNumber = float64(cha_count)
  2028. newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  2029. service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  2030. }
  2031. }
  2032. }
  2033. tx.Commit()
  2034. for _, item := range advices {
  2035. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  2036. c.ServeSuccessJSON(map[string]interface{}{
  2037. "msg": "1",
  2038. "advice": advice,
  2039. "ids": ids,
  2040. })
  2041. }
  2042. }
  2043. }
  2044. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  2045. execution_time := c.GetString("execution_time")
  2046. fmt.Println("execution_time", execution_time)
  2047. groupno, _ := c.GetInt64("groupno", -1)
  2048. //patient_id, _ := c.GetInt64("patient_id")
  2049. advice_date, _ := c.GetInt64("advice_date")
  2050. var ids []string
  2051. if groupno == 0 {
  2052. advice_ids := c.GetString("advice_id")
  2053. ids = strings.Split(advice_ids, ",")
  2054. }
  2055. if groupno < 0 {
  2056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2057. return
  2058. }
  2059. if len(execution_time) <= 0 {
  2060. utils.ErrorLog("execution_time")
  2061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2062. return
  2063. }
  2064. timeLayout2 := "2006-01-02 15:04:05"
  2065. loc, _ := time.LoadLocation("Local")
  2066. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2067. if errs != nil {
  2068. utils.ErrorLog(errs.Error())
  2069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2070. return
  2071. }
  2072. adminUserInfo := c.GetMobileAdminUserInfo()
  2073. var advice models.DoctorAdvice
  2074. if groupno > 0 {
  2075. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2076. for _, item := range advices {
  2077. if item.ExecutionState == 1 {
  2078. advice = item
  2079. }
  2080. }
  2081. } else {
  2082. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2083. for _, item := range advices {
  2084. if item.ExecutionState == 1 {
  2085. advice = item
  2086. }
  2087. }
  2088. }
  2089. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  2090. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2091. // if getPermissionErr != nil {
  2092. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2093. // return
  2094. // } else if headNursePermission == nil {
  2095. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2096. // return
  2097. // }
  2098. //}
  2099. if advice.StartTime > theTime.Unix() {
  2100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2101. return
  2102. }
  2103. advices := models.DoctorAdvice{
  2104. ExecutionTime: theTime.Unix(),
  2105. UpdatedTime: time.Now().Unix(),
  2106. }
  2107. var err error
  2108. if groupno > 0 {
  2109. // 查询信息规挡的设置天数
  2110. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2111. if infor.ID > 0 {
  2112. var cha_time int64
  2113. timeNowStr := time.Now().Format("2006-01-02")
  2114. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2115. //今日的日期减去设置的日期
  2116. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2117. if cha_time >= advices.AdviceDate {
  2118. //查询审核是否允许
  2119. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2120. //申请状态不允许的情况 拒绝修改
  2121. if infor.ApplicationStatus != 1 {
  2122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2123. return
  2124. }
  2125. }
  2126. }
  2127. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  2128. //记录日志
  2129. byterequest, _ := json.Marshal(advices)
  2130. adviceLog := models.XtDoctorAdviceLog{
  2131. UserOrgId: adminUserInfo.Org.Id,
  2132. PatientId: advices.PatientId,
  2133. AdminUserId: adminUserInfo.AdminUser.Id,
  2134. Module: 1,
  2135. ErrLog: string(byterequest),
  2136. Status: 1,
  2137. Ctime: time.Now().Unix(),
  2138. Mtime: 0,
  2139. Source: "手机端编辑医嘱",
  2140. RecordDate: advices.AdviceDate,
  2141. }
  2142. service.CreateDoctorAdviceLog(adviceLog)
  2143. redis := service.RedisClient()
  2144. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2145. redis.Set(key, "", time.Second)
  2146. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2147. redis.Set(keyOne, "", time.Second)
  2148. defer redis.Close()
  2149. } else {
  2150. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2151. if infor.ID > 0 {
  2152. var cha_time int64
  2153. timeNowStr := time.Now().Format("2006-01-02")
  2154. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2155. //今日的日期减去设置的日期
  2156. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2157. if cha_time >= advices.AdviceDate {
  2158. //查询审核是否允许
  2159. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2160. //申请状态不允许的情况 拒绝修改
  2161. if infor.ApplicationStatus != 1 {
  2162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2163. return
  2164. }
  2165. }
  2166. }
  2167. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  2168. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  2169. //记录日志
  2170. byterequest, _ := json.Marshal(advices)
  2171. adviceLog := models.XtDoctorAdviceLog{
  2172. UserOrgId: adminUserInfo.Org.Id,
  2173. PatientId: advices.PatientId,
  2174. AdminUserId: adminUserInfo.AdminUser.Id,
  2175. Module: 1,
  2176. ErrLog: string(byterequest),
  2177. Status: 1,
  2178. Ctime: time.Now().Unix(),
  2179. Mtime: 0,
  2180. Source: "手机端编辑执行医嘱",
  2181. RecordDate: advices.AdviceDate,
  2182. }
  2183. service.CreateDoctorAdviceLog(adviceLog)
  2184. redis := service.RedisClient()
  2185. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2186. redis.Set(key, "", time.Second)
  2187. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  2188. redis.Set(keyOne, "", time.Second)
  2189. defer redis.Close()
  2190. }
  2191. //判断是否开启his
  2192. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  2193. //如果开启去修改执行时间
  2194. if config.IsOpen == 1 {
  2195. advicesinfo := models.HisDoctorAdviceInfo{
  2196. ExecutionTime: theTime.Unix(),
  2197. UpdatedTime: time.Now().Unix(),
  2198. }
  2199. var advicehis models.HisDoctorAdviceInfo
  2200. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  2201. //记录日志
  2202. byterequest, _ := json.Marshal(advicesinfo)
  2203. adviceLog := models.XtDoctorAdviceLog{
  2204. UserOrgId: adminUserInfo.Org.Id,
  2205. PatientId: advices.PatientId,
  2206. AdminUserId: adminUserInfo.AdminUser.Id,
  2207. Module: 1,
  2208. ErrLog: string(byterequest),
  2209. Status: 1,
  2210. Ctime: time.Now().Unix(),
  2211. Mtime: 0,
  2212. Source: "手机端his编辑医嘱",
  2213. RecordDate: advices.AdviceDate,
  2214. }
  2215. service.CreateDoctorAdviceLog(adviceLog)
  2216. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  2217. for _, item := range his_advices {
  2218. if item.ExecutionState == 1 {
  2219. advicehis = item
  2220. }
  2221. }
  2222. redis := service.RedisClient()
  2223. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  2224. redis.Set(keyThree, "", time.Second)
  2225. recordDate := theTime.Format("2006-01-02")
  2226. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2227. redis.Set(keyFour, "", time.Second)
  2228. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  2229. redis.Set(keyFive, "", time.Second)
  2230. defer redis.Close()
  2231. project := models.HisPrescriptionProject{
  2232. ExecutionTime: theTime.Unix(),
  2233. Mtime: time.Now().Unix(),
  2234. }
  2235. service.ModifyHisPrescriptionProject(&project, ids)
  2236. //记录日志
  2237. projectquerst, _ := json.Marshal(project)
  2238. projectLog := models.XtDoctorAdviceLog{
  2239. UserOrgId: adminUserInfo.Org.Id,
  2240. PatientId: advices.PatientId,
  2241. AdminUserId: adminUserInfo.AdminUser.Id,
  2242. Module: 1,
  2243. ErrLog: string(projectquerst),
  2244. Status: 1,
  2245. Ctime: time.Now().Unix(),
  2246. Mtime: 0,
  2247. Source: "手机端his编辑项目医嘱",
  2248. RecordDate: advices.AdviceDate,
  2249. }
  2250. service.CreateDoctorAdviceLog(projectLog)
  2251. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  2252. redis.Set(keyEnd, "", time.Second)
  2253. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2254. redis.Set(keyFours, "", time.Second)
  2255. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  2256. redis.Set(keyFives, "", time.Second)
  2257. defer redis.Close()
  2258. }
  2259. if err != nil {
  2260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2261. return
  2262. }
  2263. advice.ExecutionTime = theTime.Unix()
  2264. c.ServeSuccessJSON(map[string]interface{}{
  2265. "msg": "ok",
  2266. "advice": advice,
  2267. "ids": ids,
  2268. })
  2269. return
  2270. }
  2271. func (c *PatientApiController) CheckMobileDoctorAdvice() {
  2272. origin, _ := c.GetInt64("origin", 0)
  2273. record_date, _ := c.GetInt64("record_date")
  2274. patient_id, _ := c.GetInt64("patient_id")
  2275. check_time := c.GetString("check_time")
  2276. if len(check_time) <= 0 {
  2277. utils.ErrorLog("check_time")
  2278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2279. return
  2280. }
  2281. timeLayout2 := "2006-01-02 15:04:05"
  2282. loc, _ := time.LoadLocation("Local")
  2283. theTime, errs := time.ParseInLocation(timeLayout2, check_time, loc)
  2284. fmt.Println("theTimewowowow", theTime)
  2285. if errs != nil {
  2286. utils.ErrorLog(errs.Error())
  2287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2288. return
  2289. }
  2290. if origin != 2 {
  2291. groupno, _ := c.GetInt64("groupno", -1)
  2292. var ids []string
  2293. if groupno == 0 {
  2294. advice_ids := c.GetString("advice_id")
  2295. if advice_ids == "" {
  2296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2297. return
  2298. } else {
  2299. ids = strings.Split(advice_ids, ",")
  2300. if len(ids) <= 0 {
  2301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2302. return
  2303. }
  2304. }
  2305. }
  2306. if groupno < 0 {
  2307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2308. return
  2309. }
  2310. adminUserInfo := c.GetMobileAdminUserInfo()
  2311. var advice models.DoctorAdvice
  2312. if groupno > 0 {
  2313. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2314. for _, item := range advices {
  2315. if item.CheckState == 0 {
  2316. advice = item
  2317. }
  2318. //记录日志
  2319. byterequest, _ := json.Marshal(advices)
  2320. adviceLog := models.XtDoctorAdviceLog{
  2321. UserOrgId: adminUserInfo.Org.Id,
  2322. PatientId: item.PatientId,
  2323. AdminUserId: adminUserInfo.AdminUser.Id,
  2324. Module: 3,
  2325. ErrLog: string(byterequest),
  2326. Status: 1,
  2327. Ctime: time.Now().Unix(),
  2328. Mtime: 0,
  2329. Source: "手机端核对医嘱",
  2330. RecordDate: item.AdviceDate,
  2331. }
  2332. service.CreateDoctorAdviceLog(adviceLog)
  2333. }
  2334. if advice.CheckState == 1 {
  2335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2336. return
  2337. }
  2338. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2340. return
  2341. }
  2342. } else {
  2343. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2344. for _, item := range advices {
  2345. if item.CheckState == 0 {
  2346. advice = item
  2347. }
  2348. //记录日志
  2349. byterequest, _ := json.Marshal(advices)
  2350. adviceLog := models.XtDoctorAdviceLog{
  2351. UserOrgId: adminUserInfo.Org.Id,
  2352. PatientId: item.PatientId,
  2353. AdminUserId: adminUserInfo.AdminUser.Id,
  2354. Module: 3,
  2355. ErrLog: string(byterequest),
  2356. Status: 1,
  2357. Ctime: time.Now().Unix(),
  2358. Mtime: 0,
  2359. Source: "手机端核对医嘱",
  2360. RecordDate: item.AdviceDate,
  2361. }
  2362. service.CreateDoctorAdviceLog(adviceLog)
  2363. }
  2364. if advice.CheckState == 1 {
  2365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2366. return
  2367. }
  2368. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2370. return
  2371. }
  2372. }
  2373. checker := adminUserInfo.AdminUser.Id
  2374. advices := models.DoctorAdvice{
  2375. CheckTime: theTime.Unix(),
  2376. Checker: checker,
  2377. UpdatedTime: time.Now().Unix(),
  2378. }
  2379. fmt.Println("groupnowowowowoowowow", groupno)
  2380. var err error
  2381. if groupno > 0 {
  2382. // 查询信息规挡的设置天数
  2383. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2384. if infor.ID > 0 && infor.WeekDay > 0 {
  2385. var cha_time int64
  2386. timeNowStr := time.Now().Format("2006-01-02")
  2387. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2388. //今日的日期减去设置的日期
  2389. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2390. if cha_time >= record_date {
  2391. //查询审核是否允许
  2392. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2393. //申请状态不允许的情况 拒绝修改
  2394. if infor.ApplicationStatus != 1 {
  2395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2396. return
  2397. }
  2398. }
  2399. }
  2400. err = service.CheckDoctorAdviceByGroupNoOne(&advices, groupno, adminUserInfo.Org.Id)
  2401. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2402. redis := service.RedisClient()
  2403. //清空key 值
  2404. redis.Set(key, "", time.Second)
  2405. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2406. redis.Set(keyTwo, "", time.Second)
  2407. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2408. redis.Set(keyThree, "", time.Second)
  2409. recordDate := theTime.Format("2006-01-02")
  2410. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2411. redis.Set(keyFour, "", time.Second)
  2412. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2413. redis.Set(keyFive, "", time.Second)
  2414. defer redis.Close()
  2415. } else {
  2416. if len(ids[0]) <= 0 {
  2417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2418. return
  2419. } else {
  2420. //t := time.Now().Format("2006-01-02")/**/
  2421. //timeLayout2 := "2006-01-02"
  2422. //loc, _ := time.LoadLocation("Local")
  2423. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2424. // 查询信息规挡的设置天数
  2425. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2426. if infor.ID > 0 {
  2427. var cha_time int64
  2428. timeNowStr := time.Now().Format("2006-01-02")
  2429. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2430. //今日的日期减去设置的日期
  2431. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2432. if cha_time >= advices.AdviceDate {
  2433. //查询审核是否允许
  2434. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2435. //申请状态不允许的情况 拒绝修改
  2436. if infor.ApplicationStatus != 1 {
  2437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2438. return
  2439. }
  2440. }
  2441. }
  2442. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2443. //记录日志
  2444. byterequest, _ := json.Marshal(advices)
  2445. adviceLog := models.XtDoctorAdviceLog{
  2446. UserOrgId: adminUserInfo.Org.Id,
  2447. PatientId: advices.PatientId,
  2448. AdminUserId: advices.Checker,
  2449. Module: 3,
  2450. ErrLog: string(byterequest),
  2451. Status: 1,
  2452. Ctime: time.Now().Unix(),
  2453. Mtime: 0,
  2454. Source: "手机端核对医嘱",
  2455. RecordDate: advices.AdviceDate,
  2456. }
  2457. service.CreateDoctorAdviceLog(adviceLog)
  2458. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2459. redis := service.RedisClient()
  2460. //清空key 值
  2461. redis.Set(key, "", time.Second)
  2462. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2463. redis.Set(keyTwo, "", time.Second)
  2464. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2465. redis.Set(keyThree, "", time.Second)
  2466. recordDate := theTime.Format("2006-01-02")
  2467. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2468. redis.Set(keyFour, "", time.Second)
  2469. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2470. redis.Set(keyFive, "", time.Second)
  2471. defer redis.Close()
  2472. }
  2473. }
  2474. if err != nil {
  2475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2476. return
  2477. }
  2478. advice.Checker = checker
  2479. advice.CheckTime = theTime.Unix()
  2480. advice.CheckState = 1
  2481. c.ServeSuccessJSON(map[string]interface{}{
  2482. "msg": "ok",
  2483. "advice": advice,
  2484. })
  2485. }
  2486. return
  2487. }
  2488. func (c *PatientApiController) CheckDoctorAdvice() {
  2489. origin, _ := c.GetInt64("origin", 0)
  2490. record_date, _ := c.GetInt64("record_date")
  2491. patient_id, _ := c.GetInt64("patient_id")
  2492. if origin != 2 {
  2493. groupno, _ := c.GetInt64("groupno", -1)
  2494. var ids []string
  2495. if groupno == 0 {
  2496. advice_ids := c.GetString("advice_id")
  2497. if advice_ids == "" {
  2498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2499. return
  2500. } else {
  2501. ids = strings.Split(advice_ids, ",")
  2502. if len(ids) <= 0 {
  2503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2504. return
  2505. }
  2506. }
  2507. }
  2508. if groupno < 0 {
  2509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2510. return
  2511. }
  2512. adminUserInfo := c.GetMobileAdminUserInfo()
  2513. var advice models.DoctorAdvice
  2514. if groupno > 0 {
  2515. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2516. for _, item := range advices {
  2517. if item.CheckState == 0 {
  2518. advice = item
  2519. }
  2520. //记录日志
  2521. byterequest, _ := json.Marshal(advices)
  2522. adviceLog := models.XtDoctorAdviceLog{
  2523. UserOrgId: adminUserInfo.Org.Id,
  2524. PatientId: item.PatientId,
  2525. AdminUserId: adminUserInfo.AdminUser.Id,
  2526. Module: 3,
  2527. ErrLog: string(byterequest),
  2528. Status: 1,
  2529. Ctime: time.Now().Unix(),
  2530. Mtime: 0,
  2531. Source: "手机端核对医嘱",
  2532. RecordDate: item.AdviceDate,
  2533. }
  2534. service.CreateDoctorAdviceLog(adviceLog)
  2535. }
  2536. if advice.CheckState == 1 {
  2537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2538. return
  2539. }
  2540. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2542. return
  2543. }
  2544. } else {
  2545. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2546. for _, item := range advices {
  2547. if item.CheckState == 0 {
  2548. advice = item
  2549. }
  2550. //记录日志
  2551. byterequest, _ := json.Marshal(advices)
  2552. adviceLog := models.XtDoctorAdviceLog{
  2553. UserOrgId: adminUserInfo.Org.Id,
  2554. PatientId: item.PatientId,
  2555. AdminUserId: adminUserInfo.AdminUser.Id,
  2556. Module: 3,
  2557. ErrLog: string(byterequest),
  2558. Status: 1,
  2559. Ctime: time.Now().Unix(),
  2560. Mtime: 0,
  2561. Source: "手机端核对医嘱",
  2562. RecordDate: item.AdviceDate,
  2563. }
  2564. service.CreateDoctorAdviceLog(adviceLog)
  2565. }
  2566. if advice.CheckState == 1 {
  2567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2568. return
  2569. }
  2570. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2572. return
  2573. }
  2574. }
  2575. checker := adminUserInfo.AdminUser.Id
  2576. theTime := time.Now()
  2577. advices := models.DoctorAdvice{
  2578. CheckTime: theTime.Unix(),
  2579. Checker: checker,
  2580. UpdatedTime: time.Now().Unix(),
  2581. }
  2582. var err error
  2583. if groupno > 0 {
  2584. // 查询信息规挡的设置天数
  2585. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2586. if infor.ID > 0 && infor.WeekDay > 0 {
  2587. var cha_time int64
  2588. timeNowStr := time.Now().Format("2006-01-02")
  2589. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2590. //今日的日期减去设置的日期
  2591. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2592. if cha_time >= record_date {
  2593. //查询审核是否允许
  2594. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2595. //申请状态不允许的情况 拒绝修改
  2596. if infor.ApplicationStatus != 1 {
  2597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2598. return
  2599. }
  2600. }
  2601. }
  2602. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  2603. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2604. redis := service.RedisClient()
  2605. //清空key 值
  2606. redis.Set(key, "", time.Second)
  2607. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2608. redis.Set(keyTwo, "", time.Second)
  2609. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2610. redis.Set(keyThree, "", time.Second)
  2611. recordDate := theTime.Format("2006-01-02")
  2612. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2613. redis.Set(keyFour, "", time.Second)
  2614. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2615. redis.Set(keyFive, "", time.Second)
  2616. defer redis.Close()
  2617. } else {
  2618. if len(ids[0]) <= 0 {
  2619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2620. return
  2621. } else {
  2622. //t := time.Now().Format("2006-01-02")/**/
  2623. //timeLayout2 := "2006-01-02"
  2624. //loc, _ := time.LoadLocation("Local")
  2625. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2626. // 查询信息规挡的设置天数
  2627. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2628. if infor.ID > 0 {
  2629. var cha_time int64
  2630. timeNowStr := time.Now().Format("2006-01-02")
  2631. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2632. //今日的日期减去设置的日期
  2633. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2634. if cha_time >= advices.AdviceDate {
  2635. //查询审核是否允许
  2636. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2637. //申请状态不允许的情况 拒绝修改
  2638. if infor.ApplicationStatus != 1 {
  2639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2640. return
  2641. }
  2642. }
  2643. }
  2644. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2645. //记录日志
  2646. byterequest, _ := json.Marshal(advices)
  2647. adviceLog := models.XtDoctorAdviceLog{
  2648. UserOrgId: adminUserInfo.Org.Id,
  2649. PatientId: advices.PatientId,
  2650. AdminUserId: advices.Checker,
  2651. Module: 3,
  2652. ErrLog: string(byterequest),
  2653. Status: 1,
  2654. Ctime: time.Now().Unix(),
  2655. Mtime: 0,
  2656. Source: "手机端核对医嘱",
  2657. RecordDate: advices.AdviceDate,
  2658. }
  2659. service.CreateDoctorAdviceLog(adviceLog)
  2660. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2661. redis := service.RedisClient()
  2662. //清空key 值
  2663. redis.Set(key, "", time.Second)
  2664. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2665. redis.Set(keyTwo, "", time.Second)
  2666. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2667. redis.Set(keyThree, "", time.Second)
  2668. recordDate := theTime.Format("2006-01-02")
  2669. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2670. redis.Set(keyFour, "", time.Second)
  2671. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2672. redis.Set(keyFive, "", time.Second)
  2673. defer redis.Close()
  2674. }
  2675. }
  2676. if err != nil {
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2678. return
  2679. }
  2680. advice.Checker = checker
  2681. advice.CheckTime = theTime.Unix()
  2682. advice.CheckState = 1
  2683. c.ServeSuccessJSON(map[string]interface{}{
  2684. "msg": "ok",
  2685. "advice": advice,
  2686. })
  2687. } else if origin == 2 {
  2688. adminInfo := c.GetMobileAdminUserInfo()
  2689. var ids []string
  2690. advice_ids := c.GetString("advice_id")
  2691. ids = strings.Split(advice_ids, ",")
  2692. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  2693. var err error
  2694. for _, item := range advices {
  2695. if item.CheckState == 1 {
  2696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2697. return
  2698. }
  2699. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  2700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2701. return
  2702. }
  2703. item.Checker = adminInfo.AdminUser.Id
  2704. item.CheckTime = time.Now().Unix()
  2705. item.CheckState = 1
  2706. // 查询信息规挡的设置天数
  2707. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  2708. if infor.ID > 0 {
  2709. var cha_time int64
  2710. timeNowStr := time.Now().Format("2006-01-02")
  2711. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2712. //今日的日期减去设置的日期
  2713. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2714. if cha_time >= record_date {
  2715. //查询审核是否允许
  2716. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminInfo.Org.Id, 4)
  2717. //申请状态不允许的情况 拒绝修改
  2718. if infor.ApplicationStatus != 1 {
  2719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2720. return
  2721. }
  2722. }
  2723. }
  2724. err = service.SaveHisDoctorAdvice(item)
  2725. //记录日志
  2726. byterequest, _ := json.Marshal(advices)
  2727. adviceLog := models.XtDoctorAdviceLog{
  2728. UserOrgId: adminInfo.Org.Id,
  2729. PatientId: item.PatientId,
  2730. AdminUserId: item.Checker,
  2731. Module: 3,
  2732. ErrLog: string(byterequest),
  2733. Status: 1,
  2734. Ctime: time.Now().Unix(),
  2735. Mtime: 0,
  2736. Source: "手机端核对His医嘱",
  2737. RecordDate: item.AdviceDate,
  2738. }
  2739. service.CreateDoctorAdviceLog(adviceLog)
  2740. redis := service.RedisClient()
  2741. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2742. //清空key 值
  2743. redis.Set(key, "", time.Second)
  2744. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2745. redis.Set(keyTwo, "", time.Second)
  2746. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2747. redis.Set(keyThree, "", time.Second)
  2748. theTime := time.Now()
  2749. recordDate := theTime.Format("2006-01-02")
  2750. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  2751. redis.Set(keyFour, "", time.Second)
  2752. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2753. redis.Set(keyFive, "", time.Second)
  2754. defer redis.Close()
  2755. }
  2756. if err == nil {
  2757. c.ServeSuccessJSON(map[string]interface{}{
  2758. "msg": "ok",
  2759. "advice": advices,
  2760. })
  2761. } else {
  2762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2763. return
  2764. }
  2765. }
  2766. return
  2767. }
  2768. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  2769. id, _ := c.GetInt64("patient", 0)
  2770. assessmentDate := c.GetString("assessment_date", "")
  2771. if id <= 0 || len(assessmentDate) != 10 {
  2772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2773. return
  2774. }
  2775. timeLayout := "2006-01-02"
  2776. loc, _ := time.LoadLocation("Local")
  2777. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  2778. if err != nil {
  2779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2780. return
  2781. }
  2782. theAssessmentDateTime := theTime.Unix()
  2783. adminUserInfo := c.GetMobileAdminUserInfo()
  2784. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2785. if patient.ID == 0 {
  2786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2787. return
  2788. }
  2789. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2790. if getPEErr != nil {
  2791. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  2792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2793. return
  2794. }
  2795. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2796. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2797. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2798. var evaluation models.PredialysisEvaluation
  2799. if theEvaluation != nil {
  2800. evaluation = *theEvaluation
  2801. }
  2802. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  2803. if code > 0 {
  2804. c.ServeFailJSONWithSGJErrorCode(code)
  2805. return
  2806. }
  2807. if theEvaluation == nil {
  2808. evaluation.CreatedTime = time.Now().Unix()
  2809. evaluation.Status = 1
  2810. evaluation.AssessmentDate = theAssessmentDateTime
  2811. evaluation.PatientId = id
  2812. evaluation.UserOrgId = adminUserInfo.Org.Id
  2813. if appRole.UserType == 2 || appRole.UserType == 1 {
  2814. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2815. evaluation.AssessmentTime = time.Now().Unix()
  2816. } else {
  2817. evaluation.Creater = adminUserInfo.AdminUser.Id
  2818. }
  2819. } else {
  2820. evaluation.UpdatedTime = time.Now().Unix()
  2821. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  2822. if appRole.UserType == 2 || appRole.UserType == 1 {
  2823. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2824. evaluation.AssessmentTime = time.Now().Unix()
  2825. } else {
  2826. evaluation.Modifier = adminUserInfo.AdminUser.Id
  2827. if evaluation.Creater == 0 {
  2828. evaluation.Creater = adminUserInfo.AdminUser.Id
  2829. }
  2830. }
  2831. }
  2832. //新增逻辑
  2833. var dewater_amount float64
  2834. dewater_amount = 0
  2835. if evaluation.DryWeight > 0 {
  2836. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2837. 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 {
  2838. if adminUserInfo.Org.Id != 10551 && adminUserInfo.Org.Id != 10579 && adminUserInfo.Org.Id != 10580 && adminUserInfo.Org.Id != 10585 {
  2839. dewater_amount = dewater_amount * 1000
  2840. }
  2841. }
  2842. if dewater_amount <= 0 {
  2843. dewater_amount = 0
  2844. }
  2845. } else {
  2846. dewater_amount = 0
  2847. }
  2848. // 计算透析处方的相关超滤量
  2849. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  2850. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  2851. var lastDialysisPrescribe *models.DialysisPrescription
  2852. var dialysisSolution *models.DialysisSolution
  2853. var dialysisPrescribe *models.DialysisPrescription
  2854. var system_dialysisPrescribe *models.SystemPrescription
  2855. var mode_id int64
  2856. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2857. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  2858. if schedual != nil {
  2859. // 获取透析模版
  2860. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  2861. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  2862. mode_id = schedual.ModeId
  2863. } else {
  2864. // 获取透析模版
  2865. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  2866. if dialysisPrescribe == nil && dialysisSolution != nil {
  2867. mode_id = dialysisSolution.ModeId
  2868. }
  2869. if dialysisPrescribe == nil && dialysisSolution == nil {
  2870. mode_id = 0
  2871. }
  2872. }
  2873. // 插入透析处方
  2874. if dialysisPrescribe == nil && dialysisSolution != nil {
  2875. var newprescribe models.DialysisPrescription
  2876. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2877. newprescribe.PatientId = id
  2878. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2879. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2880. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2881. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2882. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2883. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2884. newprescribe.ModeId = dialysisSolution.ModeId
  2885. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2886. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2887. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2888. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2889. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2890. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2891. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2892. newprescribe.Glucose = dialysisSolution.Glucose
  2893. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2894. newprescribe.Kalium = dialysisSolution.Kalium
  2895. newprescribe.Sodium = dialysisSolution.Sodium
  2896. newprescribe.Calcium = dialysisSolution.Calcium
  2897. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2898. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2899. newprescribe.Conductivity = dialysisSolution.Conductivity
  2900. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2901. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2902. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2903. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2904. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2905. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2906. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2907. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2908. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2909. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2910. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2911. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2912. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2913. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2914. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2915. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2916. newprescribe.CreatedTime = time.Now().Unix()
  2917. newprescribe.UpdatedTime = time.Now().Unix()
  2918. newprescribe.RecordDate = theAssessmentDateTime
  2919. newprescribe.DewaterAmount = dewater_amount
  2920. newprescribe.TargetUltrafiltration = dewater_amount
  2921. newprescribe.PrescriptionWater = dewater_amount
  2922. newprescribe.Status = 1
  2923. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  2924. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  2925. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2926. newprescribe.Remark = lastDialysisPrescription.Remark
  2927. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2928. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2929. newprescribe.ID = dialysisPrescription.ID
  2930. if dialysisPrescription.ID == 0 {
  2931. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  2932. newprescribe.Sodium = 138
  2933. newprescribe.Bicarbonate = 31.1
  2934. newprescribe.DialysateFlow = 500
  2935. newprescribe.PrescribingNumber = 1
  2936. }
  2937. if adminUserInfo.Org.Id == 10579 {
  2938. newprescribe.Modifier = 0
  2939. newprescribe.Creater = 0
  2940. newprescribe.PrescriptionDoctor = 0
  2941. }
  2942. err := service.AddSigleRecord(&newprescribe)
  2943. //记录日志
  2944. byterequest, _ := json.Marshal(newprescribe)
  2945. prescriptionLog := models.XtDialysisPrescriptionLog{
  2946. UserOrgId: adminUserInfo.Org.Id,
  2947. Ctime: time.Now().Unix(),
  2948. Mtime: 0,
  2949. ErrLog: string(byterequest),
  2950. AdminUserId: adminUserInfo.AdminUser.Id,
  2951. RecordDate: newprescribe.RecordDate,
  2952. PatientId: id,
  2953. Source: "手机端新增透前评估插入处方",
  2954. Status: 1,
  2955. }
  2956. service.CreatePrescriptionLog(prescriptionLog)
  2957. //获取key,清空redis
  2958. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2959. redis := service.RedisClient()
  2960. //清空key 值
  2961. redis.Set(key, "", time.Second)
  2962. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2963. //清空key 值
  2964. redis.Set(keyOne, "", time.Second)
  2965. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2966. //清空key 值
  2967. redis.Set(keyTwo, "", time.Second)
  2968. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2969. redis.Set(keySix, "", time.Second)
  2970. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2971. redis.Set(keySeven, "", time.Second)
  2972. if err != nil {
  2973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2974. }
  2975. } else {
  2976. if adminUserInfo.Org.Id == 10340 {
  2977. newprescribe.Sodium = 138
  2978. newprescribe.Bicarbonate = 31.1
  2979. newprescribe.DialysateFlow = 500
  2980. }
  2981. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2982. //
  2983. if appRole.UserType == 2 || appRole.UserType == 1 {
  2984. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2985. if adminUserInfo.Org.Id == 9882 {
  2986. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2987. }
  2988. }
  2989. err := service.UpDateDialysisPrescription(&newprescribe)
  2990. //记录日志
  2991. byterequest, _ := json.Marshal(newprescribe)
  2992. prescriptionLog := models.XtDialysisPrescriptionLog{
  2993. UserOrgId: adminUserInfo.Org.Id,
  2994. Ctime: time.Now().Unix(),
  2995. Mtime: 0,
  2996. ErrLog: string(byterequest),
  2997. AdminUserId: adminUserInfo.AdminUser.Id,
  2998. RecordDate: newprescribe.RecordDate,
  2999. PatientId: id,
  3000. Source: "手机端新增透前评估插入处方",
  3001. Status: 1,
  3002. }
  3003. service.CreatePrescriptionLog(prescriptionLog)
  3004. //获取key,清空redis
  3005. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3006. redis := service.RedisClient()
  3007. //清空key 值
  3008. redis.Set(key, "", time.Second)
  3009. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3010. //清空key 值
  3011. redis.Set(keyOne, "", time.Second)
  3012. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3013. //清空key 值
  3014. redis.Set(keyTwo, "", time.Second)
  3015. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3016. redis.Set(keySix, "", time.Second)
  3017. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3018. redis.Set(keySeven, "", time.Second)
  3019. if err != nil {
  3020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3021. }
  3022. }
  3023. }
  3024. if dialysisPrescribe == nil && dialysisSolution == nil {
  3025. if lastDialysisPrescribe != nil {
  3026. var newprescribe models.DialysisPrescription
  3027. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3028. newprescribe.PatientId = id
  3029. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  3030. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  3031. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  3032. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  3033. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  3034. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  3035. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  3036. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  3037. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  3038. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  3039. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  3040. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  3041. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  3042. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  3043. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  3044. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  3045. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  3046. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  3047. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  3048. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  3049. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  3050. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  3051. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  3052. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  3053. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  3054. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  3055. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  3056. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  3057. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  3058. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  3059. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  3060. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  3061. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  3062. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  3063. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  3064. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  3065. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  3066. newprescribe.CreatedTime = time.Now().Unix()
  3067. newprescribe.UpdatedTime = time.Now().Unix()
  3068. newprescribe.RecordDate = theAssessmentDateTime
  3069. newprescribe.DewaterAmount = dewater_amount
  3070. newprescribe.TargetUltrafiltration = dewater_amount
  3071. newprescribe.PrescriptionWater = 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.PrescriptionWater = dewater_amount
  3225. newprescribe.Status = 1
  3226. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  3227. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  3228. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  3229. newprescribe.Remark = lastDialysisPrescription.Remark
  3230. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  3231. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3232. newprescribe.ID = dialysisPrescription.ID
  3233. if dialysisPrescription.ID == 0 {
  3234. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3235. newprescribe.Sodium = 138
  3236. newprescribe.Bicarbonate = 31.1
  3237. newprescribe.DialysateFlow = 500
  3238. }
  3239. if adminUserInfo.Org.Id == 10579 {
  3240. newprescribe.Modifier = 0
  3241. newprescribe.Creater = 0
  3242. newprescribe.PrescriptionDoctor = 0
  3243. }
  3244. err := service.AddSigleRecord(&newprescribe)
  3245. //记录日志
  3246. byterequest, _ := json.Marshal(newprescribe)
  3247. prescriptionLog := models.XtDialysisPrescriptionLog{
  3248. UserOrgId: adminUserInfo.Org.Id,
  3249. Ctime: time.Now().Unix(),
  3250. Mtime: 0,
  3251. ErrLog: string(byterequest),
  3252. AdminUserId: adminUserInfo.AdminUser.Id,
  3253. RecordDate: newprescribe.RecordDate,
  3254. PatientId: id,
  3255. Source: "手机端新增透前评估插入处方",
  3256. Status: 1,
  3257. }
  3258. service.CreatePrescriptionLog(prescriptionLog)
  3259. //获取key,清空redis
  3260. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3261. redis := service.RedisClient()
  3262. //清空key 值
  3263. redis.Set(key, "", time.Second)
  3264. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3265. //清空key 值
  3266. redis.Set(keyOne, "", time.Second)
  3267. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3268. //清空key 值
  3269. redis.Set(keyTwo, "", time.Second)
  3270. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3271. redis.Set(keySix, "", time.Second)
  3272. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3273. redis.Set(keySeven, "", time.Second)
  3274. if err != nil {
  3275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3276. }
  3277. } else {
  3278. if adminUserInfo.Org.Id == 10340 {
  3279. newprescribe.Sodium = 138
  3280. newprescribe.Bicarbonate = 31.1
  3281. newprescribe.DialysateFlow = 500
  3282. }
  3283. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3284. //
  3285. if appRole.UserType == 2 || appRole.UserType == 1 {
  3286. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3287. if adminUserInfo.Org.Id == 9882 {
  3288. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3289. }
  3290. }
  3291. err := service.UpDateDialysisPrescription(&newprescribe)
  3292. //记录日志
  3293. byterequest, _ := json.Marshal(newprescribe)
  3294. prescriptionLog := models.XtDialysisPrescriptionLog{
  3295. UserOrgId: adminUserInfo.Org.Id,
  3296. Ctime: time.Now().Unix(),
  3297. Mtime: 0,
  3298. ErrLog: string(byterequest),
  3299. AdminUserId: adminUserInfo.AdminUser.Id,
  3300. RecordDate: newprescribe.RecordDate,
  3301. PatientId: id,
  3302. Source: "手机端新增透前评估插入处方",
  3303. Status: 1,
  3304. }
  3305. service.CreatePrescriptionLog(prescriptionLog)
  3306. //获取key,清空redis
  3307. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3308. redis := service.RedisClient()
  3309. //清空key 值
  3310. redis.Set(key, "", time.Second)
  3311. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3312. //清空key 值
  3313. redis.Set(keyOne, "", time.Second)
  3314. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3315. //清空key 值
  3316. redis.Set(keyTwo, "", time.Second)
  3317. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3318. redis.Set(keySix, "", time.Second)
  3319. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3320. redis.Set(keySeven, "", time.Second)
  3321. if err != nil {
  3322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3323. }
  3324. }
  3325. if err != nil {
  3326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3327. }
  3328. } else {
  3329. var newprescribe models.DialysisPrescription
  3330. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3331. newprescribe.PatientId = id
  3332. newprescribe.ModeId = mode_id
  3333. newprescribe.CreatedTime = time.Now().Unix()
  3334. newprescribe.UpdatedTime = time.Now().Unix()
  3335. newprescribe.RecordDate = theAssessmentDateTime
  3336. newprescribe.DewaterAmount = dewater_amount
  3337. newprescribe.TargetUltrafiltration = dewater_amount
  3338. newprescribe.Status = 1
  3339. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3340. if dialysisPrescription.ID > 0 {
  3341. newprescribe.ID = dialysisPrescription.ID
  3342. }
  3343. if dialysisPrescription.ID == 0 {
  3344. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3345. newprescribe.Sodium = 138
  3346. newprescribe.Bicarbonate = 31.1
  3347. newprescribe.DialysateFlow = 500
  3348. }
  3349. if adminUserInfo.Org.Id == 10579 {
  3350. newprescribe.Modifier = 0
  3351. newprescribe.Creater = 0
  3352. newprescribe.PrescriptionDoctor = 0
  3353. }
  3354. err := service.AddSigleRecord(&newprescribe)
  3355. //获取key,清空redis
  3356. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3357. redis := service.RedisClient()
  3358. //清空key 值
  3359. redis.Set(key, "", time.Second)
  3360. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3361. //清空key 值
  3362. redis.Set(keyOne, "", time.Second)
  3363. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3364. //清空key 值
  3365. redis.Set(keyTwo, "", time.Second)
  3366. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3367. redis.Set(keySix, "", time.Second)
  3368. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3369. redis.Set(keySeven, "", time.Second)
  3370. if err != nil {
  3371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3372. }
  3373. } else {
  3374. if adminUserInfo.Org.Id == 10340 {
  3375. newprescribe.Sodium = 138
  3376. newprescribe.Bicarbonate = 31.1
  3377. newprescribe.DialysateFlow = 500
  3378. }
  3379. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3380. //
  3381. if appRole.UserType == 2 || appRole.UserType == 1 {
  3382. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3383. if adminUserInfo.Org.Id == 9882 {
  3384. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3385. }
  3386. }
  3387. if adminUserInfo.Org.Id == 10579 {
  3388. newprescribe.Modifier = 0
  3389. newprescribe.Creater = 0
  3390. newprescribe.PrescriptionDoctor = 0
  3391. }
  3392. err := service.UpDateDialysisPrescription(&newprescribe)
  3393. //记录日志
  3394. byterequest, _ := json.Marshal(newprescribe)
  3395. prescriptionLog := models.XtDialysisPrescriptionLog{
  3396. UserOrgId: adminUserInfo.Org.Id,
  3397. Ctime: time.Now().Unix(),
  3398. Mtime: 0,
  3399. ErrLog: string(byterequest),
  3400. AdminUserId: adminUserInfo.AdminUser.Id,
  3401. RecordDate: newprescribe.RecordDate,
  3402. PatientId: id,
  3403. Source: "手机端新增透前评估插入处方",
  3404. Status: 1,
  3405. }
  3406. service.CreatePrescriptionLog(prescriptionLog)
  3407. //获取key,清空redis
  3408. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3409. redis := service.RedisClient()
  3410. //清空key 值
  3411. redis.Set(key, "", time.Second)
  3412. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3413. //清空key 值
  3414. redis.Set(keyOne, "", time.Second)
  3415. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3416. //清空key 值
  3417. redis.Set(keyTwo, "", time.Second)
  3418. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3419. redis.Set(keySix, "", time.Second)
  3420. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3421. redis.Set(keySeven, "", time.Second)
  3422. if err != nil {
  3423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3424. }
  3425. }
  3426. if err != nil {
  3427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3428. }
  3429. }
  3430. }
  3431. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  3432. // if dialysisPrescribe != nil {
  3433. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  3434. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  3435. // dialysisPrescribe.DewaterAmount = dewater_amount
  3436. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  3437. // dialysisPrescribe.Status = 1
  3438. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  3439. // if updateErr != nil {
  3440. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3441. // }
  3442. // }
  3443. // 查询信息规挡的设置天数
  3444. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3445. if infor.ID > 0 && infor.WeekDay > 0 {
  3446. var cha_time int64
  3447. timeNowStr := time.Now().Format("2006-01-02")
  3448. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3449. //今日的日期减去设置的日期
  3450. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3451. if cha_time >= evaluation.AssessmentDate {
  3452. //查询审核是否允许
  3453. infor, _ := service.GetDialysisInformationByRecordDate(id, evaluation.AssessmentDate, adminUserInfo.Org.Id, 3)
  3454. //申请状态不允许的情况 拒绝修改
  3455. if infor.ApplicationStatus != 1 {
  3456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3457. return
  3458. }
  3459. }
  3460. }
  3461. //针对长沙南雅的问题
  3462. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10164 {
  3463. if len(evaluation.SymptomBeforeDialysis) == 0 {
  3464. predialysisEvaluation, _ := service.GetPredialysisEvaluation(id, adminUserInfo.Org.Id)
  3465. evaluation.SymptomBeforeDialysis = predialysisEvaluation.SymptomBeforeDialysis
  3466. }
  3467. }
  3468. //针对孝昌康桥超滤率计算问题
  3469. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10635 {
  3470. if evaluation.ID == 0 {
  3471. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3472. if dialysisPrescribeOne.ID > 0 && evaluation.ID > 0 {
  3473. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3474. service.UpdateMobileGetDialysisPrescribe(dialysisPrescribeOne.ID, dewater_amount)
  3475. }
  3476. }
  3477. if evaluation.ID > 0 {
  3478. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3479. if dialysisPrescribeOne.ID > 0 && evaluation.ID > 0 {
  3480. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3481. service.UpdateMobileGetDialysisPrescribeOne(dialysisPrescribeOne.ID, dewater_amount)
  3482. }
  3483. }
  3484. }
  3485. err = service.UpadatePredialysisEvaluation(&evaluation)
  3486. //记录日志
  3487. byterequest, _ := json.Marshal(evaluation)
  3488. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  3489. UserOrgId: evaluation.UserOrgId,
  3490. AdminUserId: adminUserInfo.AdminUser.Id,
  3491. ErrLog: string(byterequest),
  3492. PatientId: evaluation.PatientId,
  3493. RecordDate: evaluation.AssessmentDate,
  3494. Ctime: time.Now().Unix(),
  3495. Mtime: 0,
  3496. Status: 1,
  3497. Source: "手机端保存透前评估",
  3498. }
  3499. service.CreateBeforLog(beforeDislysisLog)
  3500. finish := models.XtDialysisFinish{
  3501. IsFinish: 1,
  3502. UserOrgId: adminUserInfo.Org.Id,
  3503. Status: 1,
  3504. Ctime: time.Now().Unix(),
  3505. Mtime: 0,
  3506. Module: 3,
  3507. RecordDate: evaluation.AssessmentDate,
  3508. Sourse: 1,
  3509. PatientId: id,
  3510. }
  3511. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3, id)
  3512. if dialysisFinish.ID == 0 {
  3513. service.CreateDialysisFinish(finish)
  3514. }
  3515. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  3516. redis := service.RedisClient()
  3517. defer redis.Close()
  3518. //清空key 值
  3519. redis.Set(key, "", time.Second)
  3520. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  3521. redis.Set(keyOne, "", time.Second)
  3522. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3523. redis.Set(keyTwo, "", time.Second)
  3524. if err != nil {
  3525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  3526. return
  3527. }
  3528. c.ServeSuccessJSON(map[string]interface{}{
  3529. "msg": "ok",
  3530. "evaluation": evaluation,
  3531. })
  3532. return
  3533. }
  3534. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3535. dataBody := make(map[string]interface{}, 0)
  3536. err := json.Unmarshal(data, &dataBody)
  3537. utils.InfoLog(string(data))
  3538. if err != nil {
  3539. utils.ErrorLog(err.Error())
  3540. code = enums.ErrorCodeParamWrong
  3541. return
  3542. }
  3543. // if method == "create" {
  3544. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  3545. utils.ErrorLog("mode")
  3546. code = enums.ErrorCodeParamWrong
  3547. return
  3548. }
  3549. mode := int64(dataBody["mode"].(float64))
  3550. if mode <= 0 {
  3551. utils.ErrorLog("mode <= 0")
  3552. code = enums.ErrorCodeParamWrong
  3553. return
  3554. }
  3555. solution.ModeId = mode
  3556. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  3557. utils.ErrorLog("mode_name")
  3558. code = enums.ErrorCodeParamWrong
  3559. return
  3560. }
  3561. modeName, _ := dataBody["mode_name"].(string)
  3562. if len(modeName) == 0 {
  3563. utils.ErrorLog("len(mode_name) == 0")
  3564. code = enums.ErrorCodeParamWrong
  3565. return
  3566. }
  3567. solution.ModeName = modeName
  3568. solution.Name = modeName
  3569. // }
  3570. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3571. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3572. solution.DialysisDuration = dialysisDuration
  3573. }
  3574. if dataBody["dialysis_duration"] != nil {
  3575. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3576. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3577. solution.DialysisDuration = dialysisDuration
  3578. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  3579. dialysisDuration := dataBody["dialysis_duration"].(float64)
  3580. solution.DialysisDuration = dialysisDuration
  3581. }
  3582. }
  3583. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3584. dialyzer := int64(dataBody["dialyzer"].(float64))
  3585. solution.Dialyzer = dialyzer
  3586. }
  3587. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3588. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3589. solution.PerfusionApparatus = perfusionApparatus
  3590. }
  3591. if dataBody["blood_flow_volume"] != nil {
  3592. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3593. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3594. solution.BloodFlowVolume = bloodFlowVolume
  3595. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  3596. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  3597. solution.BloodFlowVolume = bloodFlowVolume
  3598. }
  3599. }
  3600. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3601. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3602. solution.HemodialysisMachine = hemodialysisMachine
  3603. }
  3604. if dataBody["dewater"] != nil {
  3605. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3606. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3607. solution.Dewater = dewater
  3608. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  3609. dewater := dataBody["dewater"].(float64)
  3610. solution.Dewater = dewater
  3611. }
  3612. }
  3613. if dataBody["replacement_total"] != nil {
  3614. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3615. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3616. solution.ReplacementTotal = replacementTotal
  3617. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  3618. replacementTotal := dataBody["replacement_total"].(float64)
  3619. solution.ReplacementTotal = replacementTotal
  3620. }
  3621. }
  3622. if dataBody["displace_liqui"] != nil {
  3623. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3624. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3625. solution.DisplaceLiqui = displaceLiqui
  3626. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  3627. displaceLiqui := dataBody["displace_liqui"].(float64)
  3628. solution.DisplaceLiqui = displaceLiqui
  3629. }
  3630. }
  3631. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3632. replacementWay := int64(dataBody["replacement_way"].(float64))
  3633. solution.ReplacementWay = replacementWay
  3634. }
  3635. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3636. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3637. solution.Anticoagulant = anticoagulant
  3638. }
  3639. if dataBody["anticoagulant_shouji"] != nil {
  3640. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3641. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3642. solution.AnticoagulantShouji = anticoagulantShouji
  3643. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  3644. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  3645. solution.AnticoagulantShouji = anticoagulantShouji
  3646. }
  3647. }
  3648. if dataBody["anticoagulant_weichi"] != nil {
  3649. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3650. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3651. solution.AnticoagulantWeichi = anticoagulantWeichi
  3652. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  3653. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  3654. solution.AnticoagulantWeichi = anticoagulantWeichi
  3655. }
  3656. }
  3657. if dataBody["anticoagulant_zongliang"] != nil {
  3658. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3659. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3660. solution.AnticoagulantZongliang = anticoagulantZongliang
  3661. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  3662. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  3663. solution.AnticoagulantZongliang = anticoagulantZongliang
  3664. }
  3665. }
  3666. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3667. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3668. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3669. }
  3670. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3671. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3672. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3673. }
  3674. if dataBody["kalium"] != nil {
  3675. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3676. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3677. solution.Kalium = kalium
  3678. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  3679. kalium := dataBody["kalium"].(float64)
  3680. solution.Kalium = kalium
  3681. }
  3682. }
  3683. if dataBody["sodium"] != nil {
  3684. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3685. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3686. solution.Sodium = sodium
  3687. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  3688. sodium := dataBody["sodium"].(float64)
  3689. solution.Sodium = sodium
  3690. }
  3691. }
  3692. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3693. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3694. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3695. solution.Calcium = calcium
  3696. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  3697. calcium := dataBody["calcium"].(float64)
  3698. solution.Calcium = calcium
  3699. }
  3700. }
  3701. if dataBody["bicarbonate"] != nil {
  3702. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3703. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3704. solution.Bicarbonate = bicarbonate
  3705. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  3706. bicarbonate := dataBody["bicarbonate"].(float64)
  3707. solution.Bicarbonate = bicarbonate
  3708. }
  3709. }
  3710. if dataBody["glucose"] != nil {
  3711. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3712. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3713. solution.Glucose = glucose
  3714. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  3715. glucose := dataBody["glucose"].(float64)
  3716. solution.Glucose = glucose
  3717. }
  3718. }
  3719. // if dataBody["dry_weight"] != nil {
  3720. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3721. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3722. // solution.DryWeight = dryWeight
  3723. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  3724. // dryWeight := dataBody["dry_weight"].(float64)
  3725. // solution.DryWeight = dryWeight
  3726. // }
  3727. // }
  3728. if dataBody["dialysate_flow"] != nil {
  3729. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3730. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3731. solution.DialysateFlow = dialysateFlow
  3732. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  3733. dialysateFlow := dataBody["dialysate_flow"].(float64)
  3734. solution.DialysateFlow = dialysateFlow
  3735. }
  3736. }
  3737. if dataBody["dialysate_temperature"] != nil {
  3738. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3739. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3740. solution.DialysateTemperature = dialysateTemperature
  3741. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  3742. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  3743. solution.DialysateTemperature = dialysateTemperature
  3744. }
  3745. }
  3746. if dataBody["conductivity"] != nil {
  3747. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3748. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3749. solution.Conductivity = conductivity
  3750. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  3751. conductivity := dataBody["conductivity"].(float64)
  3752. solution.Conductivity = conductivity
  3753. }
  3754. }
  3755. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3756. remark := dataBody["remark"].(string)
  3757. solution.Remark = remark
  3758. }
  3759. if dataBody["dialysis_duration_hour"] != nil {
  3760. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3761. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  3762. solution.DialysisDurationHour = dialysisDurationHour
  3763. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  3764. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  3765. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3766. }
  3767. }
  3768. if dataBody["dialysis_duration_minute"] != nil {
  3769. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3770. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  3771. solution.DialysisDurationMinute = dialysisDurationMinute
  3772. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  3773. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  3774. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3775. }
  3776. }
  3777. if dataBody["target_ultrafiltration"] != nil {
  3778. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3779. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3780. solution.TargetUltrafiltration = targetUltrafiltration
  3781. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  3782. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  3783. solution.TargetUltrafiltration = targetUltrafiltration
  3784. }
  3785. }
  3786. if dataBody["dialysate_formulation"] != nil {
  3787. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  3788. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  3789. solution.DialysateFormulation = dialysateFormulation
  3790. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3791. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  3792. solution.DialysateFormulation = int64(dialysateFormulation)
  3793. }
  3794. }
  3795. return
  3796. }
  3797. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  3798. dataBody := make(map[string]interface{}, 0)
  3799. err := json.Unmarshal(data, &dataBody)
  3800. utils.InfoLog(string(data))
  3801. if err != nil {
  3802. utils.ErrorLog(err.Error())
  3803. code = enums.ErrorCodeParamWrong
  3804. return
  3805. }
  3806. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  3807. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  3808. evaluation.WeightBefore = weightVefore
  3809. }
  3810. // fmt.Println(dataBody["dry_weight"])
  3811. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  3812. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3813. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3814. fmt.Println(additionalWeight)
  3815. evaluation.DryWeight = additionalWeight
  3816. }
  3817. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  3818. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  3819. fmt.Println(additionalWeight)
  3820. evaluation.AdditionalWeight = additionalWeight
  3821. }
  3822. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  3823. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  3824. evaluation.Temperature = Temperature
  3825. }
  3826. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  3827. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  3828. evaluation.SystolicBloodPressure = systolicBloodPressure
  3829. }
  3830. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  3831. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  3832. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  3833. }
  3834. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  3835. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  3836. evaluation.PulseFrequency = pulseFrequency
  3837. }
  3838. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  3839. breathingRate := dataBody["breathing_rate"].(string)
  3840. evaluation.BreathingRate = breathingRate
  3841. }
  3842. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  3843. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  3844. evaluation.LastPostDialysis = lastPostDialysis
  3845. }
  3846. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  3847. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  3848. evaluation.DialysisInterphase = dialysisInterphase
  3849. }
  3850. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  3851. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  3852. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  3853. }
  3854. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  3855. catheter, _ := dataBody["catheter"].(string)
  3856. evaluation.Catheter = catheter
  3857. }
  3858. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  3859. catheter_bend := int(dataBody["catheter_bend"].(float64))
  3860. evaluation.CatheterBend = catheter_bend
  3861. }
  3862. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  3863. Complication, _ := dataBody["complication"].(string)
  3864. evaluation.Complication = Complication
  3865. }
  3866. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3867. remark := dataBody["remark"].(string)
  3868. evaluation.Remark = remark
  3869. }
  3870. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  3871. machine_type := dataBody["machine_type"].(string)
  3872. evaluation.MachineType = machine_type
  3873. }
  3874. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  3875. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  3876. evaluation.BloodAccessPartId = blood_access_part_id
  3877. }
  3878. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  3879. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  3880. // evaluation.BloodAccessPartId = blood_access_part_id
  3881. //}
  3882. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  3883. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  3884. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  3885. }
  3886. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  3887. internal_fistula, _ := dataBody["internal_fistula"].(string)
  3888. evaluation.InternalFistula = internal_fistula
  3889. }
  3890. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  3891. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  3892. evaluation.InternalFistulaSkin = internal_fistula_skin
  3893. }
  3894. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  3895. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  3896. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  3897. evaluation.IsHemorrhage = is_hemorrhage
  3898. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  3899. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  3900. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  3901. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  3902. is_hemorrhage = 0
  3903. }
  3904. evaluation.IsHemorrhage = is_hemorrhage
  3905. if is_hemorrhage == 1 {
  3906. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  3907. hemorrhage, _ := dataBody["hemorrhage"].(string)
  3908. evaluation.Hemorrhage = hemorrhage
  3909. }
  3910. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  3911. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  3912. evaluation.HemorrhageOther = hemorrhage_other
  3913. }
  3914. }
  3915. } else {
  3916. evaluation.IsHemorrhage = 0
  3917. }
  3918. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  3919. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  3920. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  3921. }
  3922. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  3923. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  3924. evaluation.InternalFistulaOther = internal_fistula_other
  3925. }
  3926. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  3927. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  3928. evaluation.BloodAccessNoise = blood_access_noise
  3929. }
  3930. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  3931. //puncture_way := int64(dataBody["puncture_way"].(float64))
  3932. puncture_way := dataBody["puncture_way"].(string)
  3933. evaluation.PunctureWay = puncture_way
  3934. }
  3935. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  3936. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  3937. evaluation.VenousCatheterization = venous_catheterization
  3938. }
  3939. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  3940. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  3941. evaluation.VenousCatheterizationPart = venous_catheterization_part
  3942. }
  3943. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  3944. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  3945. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  3946. }
  3947. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  3948. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  3949. evaluation.DuctusArantii = ductus_arantii
  3950. }
  3951. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  3952. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  3953. evaluation.EmergencyTreatment = emergency_treatment
  3954. }
  3955. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  3956. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  3957. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  3958. }
  3959. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  3960. dialysis_count, _ := dataBody["dialysis_count"].(string)
  3961. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  3962. evaluation.DialysisCount = dialysis_count
  3963. }
  3964. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  3965. is_infect, _ := dataBody["is_infect"].(string)
  3966. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  3967. evaluation.IsInfect = infect
  3968. }
  3969. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  3970. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  3971. evaluation.Exposed = exposed
  3972. }
  3973. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  3974. skin, _ := dataBody["skin"].(string)
  3975. //skins, _ := strconv.ParseInt(skin, 10, 64)
  3976. evaluation.Skin = skin
  3977. }
  3978. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  3979. skin_other, _ := dataBody["skin_other"].(string)
  3980. evaluation.SkinOther = skin_other
  3981. }
  3982. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  3983. infect_other, _ := dataBody["infect_other"].(string)
  3984. evaluation.InfectOther = infect_other
  3985. }
  3986. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  3987. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  3988. evaluation.DuctusArantiiOther = ductus_arantii_other
  3989. }
  3990. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  3991. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  3992. evaluation.PunctureNeedle = punctureNeedle
  3993. }
  3994. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  3995. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  3996. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  3997. }
  3998. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  3999. pinholing := dataBody["pinholing"].(string)
  4000. evaluation.Phinholing = pinholing
  4001. }
  4002. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  4003. catheter_suture := dataBody["catheter_suture"].(string)
  4004. evaluation.CatheterSuture = catheter_suture
  4005. }
  4006. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  4007. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  4008. evaluation.CatheterSutureOther = catheter_suture_other
  4009. }
  4010. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  4011. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  4012. evaluation.UrineVolume = urine_volume
  4013. }
  4014. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  4015. edema := dataBody["edema"].(string)
  4016. evaluation.Edema = edema
  4017. }
  4018. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  4019. specialTreatment := dataBody["special_treatment"].(string)
  4020. evaluation.SpecialTreatment = specialTreatment
  4021. }
  4022. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  4023. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  4024. evaluation.CatheterMaintenance = catheter_maintenance
  4025. }
  4026. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  4027. thromubusType := int64(dataBody["thromubus_type"].(float64))
  4028. evaluation.ThromubusType = thromubusType
  4029. }
  4030. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  4031. thrombus_av := dataBody["thrombus_av"].(string)
  4032. evaluation.ThrombusAv = thrombus_av
  4033. }
  4034. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  4035. thromubus_a := dataBody["thromubus_a"].(string)
  4036. evaluation.ThromubusA = thromubus_a
  4037. }
  4038. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  4039. thromubus_v := dataBody["thromubus_v"].(string)
  4040. evaluation.ThromubusV = thromubus_v
  4041. }
  4042. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  4043. dehydration := dataBody["dehydration"].(string)
  4044. evaluation.Dehydration = dehydration
  4045. }
  4046. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  4047. period := int64(dataBody["period"].(float64))
  4048. evaluation.Period = period
  4049. }
  4050. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  4051. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  4052. evaluation.EstimatedFoodIntake = estimated_food_intake
  4053. }
  4054. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  4055. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  4056. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  4057. }
  4058. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  4059. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  4060. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  4061. }
  4062. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  4063. urea_befor := dataBody["urea_befor"].(string)
  4064. evaluation.UreaBefor = urea_befor
  4065. }
  4066. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  4067. suction := dataBody["suction"].(string)
  4068. evaluation.Suction = suction
  4069. }
  4070. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  4071. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  4072. evaluation.WeightBeforRemake = weight_befor_remake
  4073. }
  4074. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  4075. height := dataBody["height"].(string)
  4076. evaluation.Height = height
  4077. }
  4078. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  4079. age := dataBody["age"].(string)
  4080. evaluation.Age = age
  4081. }
  4082. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  4083. his_department := dataBody["his_department"].(string)
  4084. evaluation.HisDepartment = his_department
  4085. }
  4086. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  4087. his_bed := dataBody["his_bed"].(string)
  4088. evaluation.HisBed = his_bed
  4089. }
  4090. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  4091. point_puncture := dataBody["point_puncture"].(string)
  4092. evaluation.PointPuncture = point_puncture
  4093. }
  4094. if dataBody["catheter_evaluation_program"] != nil && reflect.TypeOf(dataBody["catheter_evaluation_program"]).String() == "string" {
  4095. catheter_evaluation_program := dataBody["catheter_evaluation_program"].(string)
  4096. evaluation.CatheterEvaluationProgram = catheter_evaluation_program
  4097. }
  4098. if dataBody["skin_site_catheterization"] != nil && reflect.TypeOf(dataBody["skin_site_catheterization"]).String() == "string" {
  4099. skin_site_catheterization := dataBody["skin_site_catheterization"].(string)
  4100. evaluation.SkinSiteCatheterization = skin_site_catheterization
  4101. }
  4102. if dataBody["whether_unobstructed"] != nil && reflect.TypeOf(dataBody["whether_unobstructed"]).String() == "float64" {
  4103. whether_unobstructed := int64(dataBody["whether_unobstructed"].(float64))
  4104. evaluation.WhetherUnobstructed = whether_unobstructed
  4105. }
  4106. if dataBody["lien_necessary"] != nil && reflect.TypeOf(dataBody["lien_necessary"]).String() == "float64" {
  4107. lien_necessary := int64(dataBody["lien_necessary"].(float64))
  4108. evaluation.LienNecessary = lien_necessary
  4109. }
  4110. if dataBody["pathway_formation_time"] != nil && reflect.TypeOf(dataBody["pathway_formation_time"]).String() == "string" {
  4111. pathway_formation_time := dataBody["pathway_formation_time"].(string)
  4112. timeLayout := "2006-01-02"
  4113. loc, _ := time.LoadLocation("Local")
  4114. var startTime int64
  4115. if len(pathway_formation_time) > 0 {
  4116. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  4117. startTime = theTime.Unix()
  4118. }
  4119. evaluation.PathwayFormationTime = startTime
  4120. }
  4121. if dataBody["befor_symptoms"] != nil && reflect.TypeOf(dataBody["befor_symptoms"]).String() == "string" {
  4122. befor_symptoms := dataBody["befor_symptoms"].(string)
  4123. evaluation.BeforSymptoms = befor_symptoms
  4124. }
  4125. if dataBody["washing_time"] != nil && reflect.TypeOf(dataBody["washing_time"]).String() == "string" {
  4126. washing_time, _ := dataBody["washing_time"].(string)
  4127. evaluation.WashingTime = washing_time
  4128. }
  4129. if dataBody["warsh_count"] != nil && reflect.TypeOf(dataBody["warsh_count"]).String() == "string" {
  4130. warsh_count, _ := dataBody["warsh_count"].(string)
  4131. evaluation.WarshCount = warsh_count
  4132. }
  4133. if dataBody["puncture_needle_direction"] != nil && reflect.TypeOf(dataBody["puncture_needle_direction"]).String() == "string" {
  4134. puncture_needle_direction, _ := dataBody["puncture_needle_direction"].(string)
  4135. evaluation.PunctureNeedleDirection = puncture_needle_direction
  4136. }
  4137. if dataBody["symptom_before_dialysis_other"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis_other"]).String() == "string" {
  4138. symptom_before_dialysis_other, _ := dataBody["symptom_before_dialysis_other"].(string)
  4139. evaluation.SymptomBeforeDialysisOther = symptom_before_dialysis_other
  4140. }
  4141. return
  4142. }
  4143. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  4144. dataBody := make(map[string]interface{}, 0)
  4145. err := json.Unmarshal(data, &dataBody)
  4146. if err != nil {
  4147. utils.ErrorLog(err.Error())
  4148. code = enums.ErrorCodeParamWrong
  4149. return
  4150. }
  4151. timeLayout := "2006-01-02"
  4152. loc, _ := time.LoadLocation("Local")
  4153. isChild := false
  4154. if action == "create" {
  4155. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4156. utils.ErrorLog("advice_type")
  4157. code = enums.ErrorCodeParamWrong
  4158. return
  4159. }
  4160. adviceType := int64(dataBody["advice_type"].(float64))
  4161. if adviceType != 1 && adviceType != 2 {
  4162. utils.ErrorLog("advice_type != 1&&2")
  4163. code = enums.ErrorCodeParamWrong
  4164. return
  4165. }
  4166. advice.AdviceType = adviceType
  4167. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4168. utils.ErrorLog("advice_date")
  4169. code = enums.ErrorCodeParamWrong
  4170. return
  4171. }
  4172. adviceDate, _ := dataBody["advice_date"].(string)
  4173. if len(adviceDate) == 0 {
  4174. utils.ErrorLog("len(adviceDate) == 0")
  4175. code = enums.ErrorCodeParamWrong
  4176. return
  4177. }
  4178. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4179. if err != nil {
  4180. utils.ErrorLog(err.Error())
  4181. code = enums.ErrorCodeParamWrong
  4182. return
  4183. }
  4184. advice.AdviceDate = theTime.Unix()
  4185. advice.RecordDate = theTime.Unix()
  4186. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  4187. parentId := int64(dataBody["parent_id"].(float64))
  4188. advice.ParentId = parentId
  4189. if parentId > 0 {
  4190. isChild = true
  4191. }
  4192. }
  4193. } else {
  4194. isChild = advice.ParentId > 0
  4195. }
  4196. if !isChild {
  4197. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4198. utils.ErrorLog("start_time")
  4199. code = enums.ErrorCodeParamWrong
  4200. return
  4201. }
  4202. startTime, _ := dataBody["start_time"].(string)
  4203. if len(startTime) == 0 {
  4204. utils.ErrorLog("len(start_time) == 0")
  4205. code = enums.ErrorCodeParamWrong
  4206. return
  4207. }
  4208. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  4209. if err != nil {
  4210. utils.ErrorLog(err.Error())
  4211. code = enums.ErrorCodeParamWrong
  4212. return
  4213. }
  4214. advice.StartTime = theTime.Unix()
  4215. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4216. deliveryWay, _ := dataBody["delivery_way"].(string)
  4217. advice.DeliveryWay = deliveryWay
  4218. }
  4219. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4220. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4221. advice.ExecutionFrequency = executionFrequency
  4222. }
  4223. }
  4224. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4225. deliveryWay, _ := dataBody["delivery_way"].(string)
  4226. advice.DeliveryWay = deliveryWay
  4227. }
  4228. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4229. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4230. advice.ExecutionFrequency = executionFrequency
  4231. }
  4232. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  4233. utils.ErrorLog("advice_name")
  4234. code = enums.ErrorCodeParamWrong
  4235. return
  4236. }
  4237. adviceName, _ := dataBody["advice_name"].(string)
  4238. if len(adviceName) == 0 {
  4239. utils.ErrorLog("len(advice_name) == 0")
  4240. code = enums.ErrorCodeParamWrong
  4241. return
  4242. }
  4243. advice.AdviceName = adviceName
  4244. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  4245. adviceDsc, _ := dataBody["advice_desc"].(string)
  4246. advice.AdviceDesc = adviceDsc
  4247. }
  4248. if dataBody["way"] == nil {
  4249. advice.Way = 0
  4250. } else {
  4251. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  4252. way := int64(dataBody["way"].(float64))
  4253. advice.Way = way
  4254. }
  4255. }
  4256. if dataBody["drug_id"] == nil {
  4257. advice.DrugId = 0
  4258. } else {
  4259. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  4260. drug_id := int64(dataBody["drug_id"].(float64))
  4261. advice.DrugId = drug_id
  4262. }
  4263. }
  4264. if dataBody["drug_name_id"] == nil {
  4265. advice.DrugNameId = 0
  4266. } else {
  4267. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  4268. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  4269. advice.DrugNameId = drug_name_id
  4270. }
  4271. }
  4272. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  4273. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  4274. advice.SingleDose = singleDose
  4275. }
  4276. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  4277. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  4278. advice.SingleDoseUnit = singleDoseUnit
  4279. }
  4280. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  4281. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  4282. advice.DrugSpec = drugSpec
  4283. }
  4284. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  4285. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  4286. advice.DrugSpecUnit = drugSpecUnit
  4287. }
  4288. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  4289. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  4290. advice.PrescribingNumber = prescribingNumber
  4291. }
  4292. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  4293. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  4294. advice.PrescribingNumberUnit = prescribingNumberUnit
  4295. }
  4296. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4297. remark, _ := dataBody["remark"].(string)
  4298. advice.Remark = remark
  4299. }
  4300. return
  4301. }
  4302. func (c *PatientApiController) GetPatientEducation() {
  4303. patientID, _ := c.GetInt64("patient_id", 0)
  4304. page, _ := c.GetInt64("page", 0)
  4305. limit, _ := c.GetInt64("limit", 0)
  4306. startTime := c.GetString("start_time", "")
  4307. endTime := c.GetString("end_time", "")
  4308. if page <= 0 {
  4309. page = 1
  4310. }
  4311. if limit <= 0 {
  4312. limit = 10
  4313. }
  4314. if patientID <= 0 {
  4315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4316. return
  4317. }
  4318. timeLayout := "2006-01-02"
  4319. loc, _ := time.LoadLocation("Local")
  4320. var theStartTIme int64
  4321. if len(startTime) > 0 {
  4322. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4323. if err != nil {
  4324. theStartTIme = 0
  4325. }
  4326. theStartTIme = theTime.Unix()
  4327. }
  4328. var theEndtTIme int64
  4329. if len(endTime) > 0 {
  4330. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4331. if err != nil {
  4332. theEndtTIme = 0
  4333. }
  4334. theEndtTIme = theTime.Unix()
  4335. }
  4336. adminUserInfo := c.GetMobileAdminUserInfo()
  4337. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  4338. c.ServeSuccessJSON(map[string]interface{}{
  4339. "total": total,
  4340. "edus": edus,
  4341. })
  4342. return
  4343. }
  4344. func (c *PatientApiController) GetPatientSchedulesList() {
  4345. patientID, _ := c.GetInt64("patient_id", 0)
  4346. page, _ := c.GetInt64("page", 0)
  4347. limit, _ := c.GetInt64("limit", 0)
  4348. if patientID <= 0 {
  4349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4350. return
  4351. }
  4352. adminUserInfo := c.GetMobileAdminUserInfo()
  4353. todayTime := time.Now().Format("2006-01-02")
  4354. timeLayout := "2006-01-02 15:04:05"
  4355. loc, _ := time.LoadLocation("Local")
  4356. var theStartTime int64
  4357. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  4358. theStartTime = theTime.Unix()
  4359. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  4360. if len(schedules) > 0 {
  4361. for index, item := range schedules {
  4362. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  4363. schedules[index].Week = int64(week)
  4364. }
  4365. }
  4366. c.ServeSuccessJSON(map[string]interface{}{
  4367. "schedules": schedules,
  4368. })
  4369. return
  4370. }
  4371. func (c *PatientApiController) GetRecords() {
  4372. patientID, _ := c.GetInt64("patient_id", 0)
  4373. page, _ := c.GetInt64("page", 0)
  4374. limit, _ := c.GetInt64("limit", 0)
  4375. startTime := c.GetString("start_time", "")
  4376. endTime := c.GetString("end_time", "")
  4377. mode_id, _ := c.GetInt64("mode_id", 0)
  4378. if page <= 0 {
  4379. page = 1
  4380. }
  4381. if limit <= 0 {
  4382. limit = 10
  4383. }
  4384. if patientID <= 0 {
  4385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4386. return
  4387. }
  4388. timeLayout := "2006-01-02"
  4389. loc, _ := time.LoadLocation("Local")
  4390. var theStartTIme int64
  4391. if len(startTime) > 0 {
  4392. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4393. if err != nil {
  4394. theStartTIme = 0
  4395. }
  4396. theStartTIme = theTime.Unix()
  4397. }
  4398. var theEndtTIme int64
  4399. if len(endTime) > 0 {
  4400. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4401. if err != nil {
  4402. theEndtTIme = 0
  4403. }
  4404. theEndtTIme = theTime.Unix()
  4405. }
  4406. adminUserInfo := c.GetMobileAdminUserInfo()
  4407. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  4408. c.ServeSuccessJSON(map[string]interface{}{
  4409. "total": total,
  4410. "records": records,
  4411. })
  4412. return
  4413. }
  4414. func (c *PatientApiController) GetPatientMonitor() {
  4415. partition, _ := c.GetInt64("partition")
  4416. monitorDate := c.GetString("date")
  4417. patient_id, _ := c.GetInt64("patient_id")
  4418. timeLayout := "2006-01-02"
  4419. loc, _ := time.LoadLocation("Local")
  4420. var theStartTime int64
  4421. if len(monitorDate) > 0 {
  4422. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  4423. if err != nil {
  4424. theStartTime = 0
  4425. }
  4426. theStartTime = theTime.Unix()
  4427. }
  4428. adminInfo := c.GetMobileAdminUserInfo()
  4429. orgID := adminInfo.Org.Id
  4430. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  4431. if err != nil {
  4432. c.ErrorLog("获取排班信息失败:%v", err)
  4433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4434. } else {
  4435. if len(monitor) > 0 {
  4436. //获取所有床位
  4437. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  4438. //获取所有分区
  4439. zoneList, _ := service.GetAllZoneByList(orgID)
  4440. //获取透析处方
  4441. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  4442. //获取透前评估
  4443. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  4444. //获取上机
  4445. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  4446. //获取透后
  4447. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  4448. //获取透后监测
  4449. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  4450. //获取所有的患者
  4451. patients, _ := service.GetAllPatientListByListOne(orgID)
  4452. for _, it := range patients {
  4453. if orgID == 10445 {
  4454. if theStartTime <= 1703952000 {
  4455. listOne, _ := service.GetDialysisOrderCountTwentyEight(orgID, it.ID, theStartTime)
  4456. it.TotalDialysis = listOne.Count
  4457. }
  4458. if theStartTime >= 1704038400 {
  4459. listOrder, _ := service.GetDialysisOrderCountTenEight(it.ID, theStartTime)
  4460. it.TotalDialysis = listOrder.Count
  4461. }
  4462. }
  4463. }
  4464. //获取所有透析模式
  4465. treatments, _ := service.GetAllTreatModeByList(orgID)
  4466. for key, item := range monitor {
  4467. // 获取床位信息
  4468. for _, it := range numberList {
  4469. if item.BedId == it.ID {
  4470. monitor[key].DeviceNumber = it
  4471. break
  4472. }
  4473. }
  4474. //获取分区信息
  4475. for _, it := range zoneList {
  4476. if item.PartitionId == it.ID {
  4477. monitor[key].DeviceZone = it
  4478. }
  4479. }
  4480. for _, prescription := range prescriptions {
  4481. if item.PatientId == prescription.PatientId {
  4482. monitor[key].Prescription = prescription
  4483. break
  4484. }
  4485. }
  4486. // 透前评估
  4487. for _, assessmentBefore := range assessmentBefores {
  4488. if item.PatientId == assessmentBefore.PatientId {
  4489. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  4490. break
  4491. }
  4492. }
  4493. // 透析上下机
  4494. for _, dialysisOrder := range dialysisOrders {
  4495. if item.PatientId == dialysisOrder.PatientId {
  4496. monitor[key].DialysisOrder = dialysisOrder
  4497. break
  4498. }
  4499. }
  4500. // 治疗小节
  4501. for _, afterDislysis := range AssessmentAfterDislysis {
  4502. if item.PatientId == afterDislysis.PatientId {
  4503. monitor[key].AssessmentAfterDislysis = afterDislysis
  4504. break
  4505. }
  4506. }
  4507. for _, it := range monitorlist {
  4508. if item.PatientId == it.PatientId {
  4509. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  4510. }
  4511. }
  4512. for _, patient := range patients {
  4513. if item.PatientId == patient.ID {
  4514. monitor[key].MonitorPatients = patient
  4515. break
  4516. }
  4517. }
  4518. for _, treatment := range treatments {
  4519. if item.ModeId == treatment.ID {
  4520. monitor[key].TreatmentMode = treatment
  4521. break
  4522. }
  4523. }
  4524. }
  4525. }
  4526. }
  4527. //获取患者的透析次数
  4528. //count, err := service.GetDialysisCount(orgID, partition)
  4529. patients, err := service.GetAllpatientFourty(orgID)
  4530. if err == nil {
  4531. c.ServeSuccessJSON(map[string]interface{}{
  4532. "monitor": monitor,
  4533. //"patientCount": count,
  4534. "patients": patients,
  4535. })
  4536. } else {
  4537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4538. }
  4539. }
  4540. // /m/api/monitor/patient [get] 搜索病人的测量记录
  4541. // @param keyword:string 病人姓名或透析号
  4542. // @param page:int
  4543. func (this *PatientApiController) SearchMonitorPatient() {
  4544. keyword := this.GetString("keyword")
  4545. page, _ := this.GetInt("page")
  4546. if page <= 0 {
  4547. page = 1
  4548. }
  4549. if len(keyword) == 0 {
  4550. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4551. return
  4552. }
  4553. adminUserInfo := this.GetMobileAdminUserInfo()
  4554. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  4555. if getMonitorErr != nil {
  4556. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4557. return
  4558. } else {
  4559. this.ServeSuccessJSON(map[string]interface{}{
  4560. "monitor": monitors,
  4561. })
  4562. }
  4563. }
  4564. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  4565. id, _ := c.GetInt64("id", 0)
  4566. page, _ := c.GetInt64("page", 0)
  4567. limit, _ := c.GetInt64("limit", 0)
  4568. if id <= 0 {
  4569. c.ServeSuccessJSON(map[string]interface{}{
  4570. "solutions": nil,
  4571. })
  4572. return
  4573. }
  4574. if page <= 0 {
  4575. page = 1
  4576. }
  4577. if limit <= 0 {
  4578. limit = 10
  4579. }
  4580. adminInfo := c.GetMobileAdminUserInfo()
  4581. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  4582. c.ServeSuccessJSON(map[string]interface{}{
  4583. "solutions": solutions,
  4584. "total": total,
  4585. })
  4586. return
  4587. }
  4588. // GetDoctorAdvices 医嘱列表
  4589. func (c *PatientApiController) GetDoctorAdvices() {
  4590. id, _ := c.GetInt64("id", 0)
  4591. adviceType, _ := c.GetInt64("advice_type", 0)
  4592. stopType, _ := c.GetInt64("stop_state", 0)
  4593. startTime := c.GetString("start_time", "")
  4594. endTime := c.GetString("end_time", "")
  4595. keywords := c.GetString("keywords", "")
  4596. need, _ := c.GetInt64("need_doctor", 0)
  4597. adminUserInfo := c.GetMobileAdminUserInfo()
  4598. timeLayout := "2006-01-02"
  4599. loc, _ := time.LoadLocation("Local")
  4600. var theStartTIme int64
  4601. if len(startTime) > 0 {
  4602. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4603. if err != nil {
  4604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4605. return
  4606. }
  4607. theStartTIme = theTime.Unix()
  4608. }
  4609. var theEndtTIme int64
  4610. if len(endTime) > 0 {
  4611. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4612. if err != nil {
  4613. utils.ErrorLog(err.Error())
  4614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4615. return
  4616. }
  4617. theEndtTIme = theTime.Unix()
  4618. }
  4619. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  4620. if need == 1 {
  4621. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4622. c.ServeSuccessJSON(map[string]interface{}{
  4623. "advices": advices,
  4624. "total": total,
  4625. "users": users,
  4626. })
  4627. } else {
  4628. c.ServeSuccessJSON(map[string]interface{}{
  4629. "advices": advices,
  4630. "total": total,
  4631. "users": []string{},
  4632. })
  4633. }
  4634. return
  4635. }
  4636. func (c *PatientApiController) GetPrintDialysisOrder() {
  4637. xtno := c.GetString("xtno")
  4638. xtdate := c.GetString("xtdate")
  4639. timeLayout := "2006-01-02"
  4640. loc, _ := time.LoadLocation("Local")
  4641. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  4642. if err != nil {
  4643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4644. return
  4645. }
  4646. xttime := theTime.Unix()
  4647. //获取当前日期月份的第一天
  4648. firstmonth := service.GetFirstDateOfMonth(theTime)
  4649. firstMonthDate := firstmonth.Unix()
  4650. operatorIDs := make([]int64, 0)
  4651. adminUserInfo := c.GetMobileAdminUserInfo()
  4652. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4653. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  4654. //透析单
  4655. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4656. if dialysisOrder != nil {
  4657. if dialysisOrder.FinishNurse > 0 {
  4658. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  4659. }
  4660. if dialysisOrder.StartNurse > 0 {
  4661. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  4662. }
  4663. }
  4664. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4665. //透前评估
  4666. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4667. //透后评估
  4668. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4669. if AssessmentAfterDislysis.Modifier > 0 {
  4670. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  4671. }
  4672. //透析处方
  4673. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4674. if dialysisPrescription.PrescriptionDoctor > 0 {
  4675. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  4676. }
  4677. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4678. patientInfo.TotalDialysis = dialysis_count
  4679. //临时医嘱
  4680. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4681. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4682. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  4683. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  4684. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4685. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4686. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4687. for _, item := range projects {
  4688. cnt, _ := strconv.ParseFloat(item.Count, 64)
  4689. var advice models.HisDoctorAdviceInfo
  4690. advice.ID = item.ID
  4691. advice.Checker = item.Checker
  4692. advice.CheckTime = item.CheckTime
  4693. advice.CheckState = item.CheckState
  4694. advice.ExecutionState = item.ExecutionState
  4695. advice.ExecutionStaff = item.ExecutionStaff
  4696. //advice.PrescribingNumber = float64(item.Count)
  4697. advice.PrescribingNumber = cnt
  4698. advice.PrescribingNumberUnit = item.Unit
  4699. advice.AdviceDoctor = item.Doctor
  4700. if item.Type == 3 {
  4701. advice.AdviceName = item.GoodInfo.GoodName
  4702. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  4703. } else if item.Type == 2 {
  4704. advice.AdviceName = item.HisProject.ProjectName
  4705. }
  4706. advice.StartTime = item.StartTime
  4707. hisAdvice = append(hisAdvice, &advice)
  4708. }
  4709. }
  4710. if len(DoctorAdvice) > 0 {
  4711. for _, item := range DoctorAdvice {
  4712. if item.AdviceDoctor > 0 {
  4713. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  4714. }
  4715. if item.ExecutionStaff > 0 {
  4716. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  4717. }
  4718. if item.Checker > 0 {
  4719. operatorIDs = append(operatorIDs, item.Checker)
  4720. }
  4721. }
  4722. }
  4723. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4724. //透析监测
  4725. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4726. //透析小结
  4727. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4728. //接诊评估
  4729. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4730. //相关操作对应的操作人
  4731. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  4732. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  4733. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4734. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4735. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  4736. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4737. if config.IsOpen == 1 {
  4738. c.ServeSuccessJSON(map[string]interface{}{
  4739. "users": adminUser,
  4740. "patientInfo": patientInfo,
  4741. "PredialysisEvaluation": PredialysisEvaluation,
  4742. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4743. "dialysisPrescription": dialysisPrescription,
  4744. "advices": hisAdvice,
  4745. "monitors": Record,
  4746. "summary": TreatmentSummary,
  4747. "receiverTreatmentAccess": receiverTreatmentAccess,
  4748. "dialysisOrder": dialysisOrder,
  4749. "operators": operators,
  4750. "org_template_info": templateInfo,
  4751. "check": check,
  4752. "dialysiscount": dialysiscount,
  4753. "last_order": last_order,
  4754. "projects": projects,
  4755. "project_config": project_config,
  4756. "lastWeight": lastWeight,
  4757. "lastSchedule": lastSchedule,
  4758. "DoctorAdvice": DoctorAdvice,
  4759. "hisAdvice": hisAdvice,
  4760. })
  4761. }
  4762. if config.IsOpen == 0 || config.IsOpen == 2 {
  4763. c.ServeSuccessJSON(map[string]interface{}{
  4764. "users": adminUser,
  4765. "patientInfo": patientInfo,
  4766. "PredialysisEvaluation": PredialysisEvaluation,
  4767. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4768. "dialysisPrescription": dialysisPrescription,
  4769. "advices": DoctorAdvice,
  4770. "monitors": Record,
  4771. "summary": TreatmentSummary,
  4772. "receiverTreatmentAccess": receiverTreatmentAccess,
  4773. "dialysisOrder": dialysisOrder,
  4774. "operators": operators,
  4775. "org_template_info": templateInfo,
  4776. "check": check,
  4777. "dialysiscount": dialysiscount,
  4778. "last_order": last_order,
  4779. "projects": projects,
  4780. "project_config": project_config,
  4781. "lastWeight": lastWeight,
  4782. "lastSchedule": lastSchedule,
  4783. "DoctorAdvice": DoctorAdvice,
  4784. "hisAdvice": hisAdvice,
  4785. })
  4786. }
  4787. }
  4788. func (c *PatientApiController) CreateGroupAdvice() {
  4789. is_child, _ := c.GetInt64("is_child", 0)
  4790. if is_child == 1 {
  4791. patient, _ := c.GetInt64("id", 0)
  4792. if patient <= 0 {
  4793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4794. return
  4795. }
  4796. adminUserInfo := c.GetMobileAdminUserInfo()
  4797. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  4798. if patientInfo.ID == 0 {
  4799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4800. return
  4801. }
  4802. group_no, _ := c.GetInt64("group_no")
  4803. if group_no <= 0 {
  4804. group_no = 0
  4805. }
  4806. dataBody := make(map[string]interface{}, 0)
  4807. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4808. if err != nil {
  4809. utils.ErrorLog(err.Error())
  4810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4811. return
  4812. }
  4813. timeLayout := "2006-01-02"
  4814. loc, _ := time.LoadLocation("Local")
  4815. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4816. utils.ErrorLog("advice_type")
  4817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4818. return
  4819. }
  4820. adviceType := int64(dataBody["advice_type"].(float64))
  4821. if adviceType != 1 && adviceType != 2 {
  4822. utils.ErrorLog("advice_type != 1&&2")
  4823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4824. return
  4825. }
  4826. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4827. utils.ErrorLog("start_time")
  4828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4829. return
  4830. }
  4831. startTime2, _ := dataBody["start_time"].(string)
  4832. time_arr := strings.Split(startTime2, " ")
  4833. if len(time_arr) > 0 {
  4834. startTime2 = time_arr[0]
  4835. }
  4836. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4837. utils.ErrorLog("advice_date")
  4838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4839. return
  4840. }
  4841. advice_date, _ := dataBody["advice_date"].(string)
  4842. var advicedateunix int64
  4843. if len(advice_date) > 0 {
  4844. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  4845. if err != nil {
  4846. fmt.Println(err)
  4847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4848. return
  4849. }
  4850. advicedateunix = theTime.Unix()
  4851. }
  4852. adviceDate := startTime2
  4853. if len(adviceDate) == 0 {
  4854. utils.ErrorLog("len(adviceDate) == 0")
  4855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4856. return
  4857. }
  4858. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4859. if err != nil {
  4860. utils.ErrorLog(err.Error())
  4861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4862. return
  4863. }
  4864. AdviceDate := advicedateunix
  4865. RecordDate := advicedateunix
  4866. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4867. utils.ErrorLog("start_time")
  4868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4869. return
  4870. }
  4871. startTime, _ := dataBody["start_time"].(string)
  4872. if len(startTime) == 0 {
  4873. utils.ErrorLog("len(start_time) == 0")
  4874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4875. return
  4876. }
  4877. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  4878. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  4879. if err != nil {
  4880. utils.ErrorLog(err.Error())
  4881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4882. return
  4883. }
  4884. StartTime := theTime.Unix()
  4885. Remark := ""
  4886. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4887. remark, _ := dataBody["remark"].(string)
  4888. Remark = remark
  4889. }
  4890. Startdate := int64(dataBody["record_date"].(float64))
  4891. var advices []*models.GroupAdvice
  4892. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  4893. utils.ErrorLog("adviceNames")
  4894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4895. return
  4896. }
  4897. adviceNames := dataBody["adviceNames"].([]interface{})
  4898. for _, adviceNameMap := range adviceNames {
  4899. adviceNameM := adviceNameMap.(map[string]interface{})
  4900. var advice models.GroupAdvice
  4901. advice.Remark = Remark
  4902. advice.AdviceType = adviceType
  4903. advice.StartTime = StartTime
  4904. if adminUserInfo.Org.Id == 10340 {
  4905. advice.AdviceDate = AdviceDate
  4906. advice.RecordDate = RecordDate
  4907. }
  4908. if adminUserInfo.Org.Id != 10340 {
  4909. advice.AdviceDate = theTimeOne.Unix()
  4910. advice.RecordDate = theTimeOne.Unix()
  4911. }
  4912. advice.Status = 1
  4913. advice.CreatedTime = time.Now().Unix()
  4914. advice.UpdatedTime = time.Now().Unix()
  4915. advice.StopState = 2
  4916. advice.ExecutionState = 2
  4917. advice.UserOrgId = adminUserInfo.Org.Id
  4918. advice.PatientId = patientInfo.ID
  4919. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4920. advice.IsSettle = 2
  4921. //入口
  4922. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  4923. if errcode > 0 {
  4924. c.ServeFailJSONWithSGJErrorCode(errcode)
  4925. return
  4926. }
  4927. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  4928. subdrugs := adviceNameM["subdrugs"].([]interface{})
  4929. if len(subdrugs) > 0 {
  4930. for _, subdrug := range subdrugs {
  4931. var s models.GroupAdvice
  4932. s.Remark = Remark
  4933. s.AdviceType = adviceType
  4934. s.StartTime = StartTime
  4935. s.AdviceDate = AdviceDate
  4936. s.RecordDate = RecordDate
  4937. s.Status = 1
  4938. s.CreatedTime = time.Now().Unix()
  4939. s.UpdatedTime = time.Now().Unix()
  4940. s.StopState = 2
  4941. s.ExecutionState = 2
  4942. s.UserOrgId = adminUserInfo.Org.Id
  4943. s.PatientId = patientInfo.ID
  4944. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  4945. s.IsSettle = 2
  4946. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  4947. if errcode > 0 {
  4948. c.ServeFailJSONWithSGJErrorCode(errcode)
  4949. return
  4950. }
  4951. advice.Children = append(advice.Children, &s)
  4952. }
  4953. }
  4954. }
  4955. //长沙南雅
  4956. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  4957. //查询该患者今日有没有双人核对
  4958. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  4959. if check.ID > 0 {
  4960. advice.Checker = check.Modifier
  4961. advice.CheckState = 1
  4962. advice.CheckTime = time.Now().Unix()
  4963. }
  4964. }
  4965. advices = append(advices, &advice)
  4966. }
  4967. // 查询信息规挡的设置天数
  4968. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4969. if infor.ID > 0 && infor.WeekDay > 0 {
  4970. var cha_time int64
  4971. timeNowStr := time.Now().Format("2006-01-02")
  4972. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4973. //今日的日期减去设置的日期
  4974. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4975. if cha_time >= Startdate {
  4976. //查询审核是否允许
  4977. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id, 5)
  4978. //申请状态不允许的情况 拒绝修改
  4979. if infor.ApplicationStatus != 1 {
  4980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4981. return
  4982. }
  4983. }
  4984. }
  4985. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  4986. for _, item := range advices {
  4987. //记录日志
  4988. byterequest, _ := json.Marshal(item)
  4989. adviceLog := models.XtDoctorAdviceLog{
  4990. UserOrgId: item.UserOrgId,
  4991. PatientId: item.PatientId,
  4992. AdminUserId: adminUserInfo.AdminUser.Id,
  4993. Module: 1,
  4994. ErrLog: string(byterequest),
  4995. Status: 1,
  4996. Ctime: time.Now().Unix(),
  4997. Mtime: 0,
  4998. Source: "手机端新增医嘱",
  4999. RecordDate: item.AdviceDate,
  5000. }
  5001. service.CreateDoctorAdviceLog(adviceLog)
  5002. }
  5003. finish := models.XtDialysisFinish{
  5004. IsFinish: 1,
  5005. UserOrgId: adminUserInfo.Org.Id,
  5006. Status: 1,
  5007. Ctime: time.Now().Unix(),
  5008. Mtime: 0,
  5009. Module: 4,
  5010. RecordDate: advicedateunix,
  5011. Sourse: 1,
  5012. PatientId: patient,
  5013. }
  5014. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4, patient)
  5015. if dialysisFinish.ID == 0 {
  5016. service.CreateDialysisFinish(finish)
  5017. }
  5018. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  5019. redis := service.RedisClient()
  5020. //清空key 值
  5021. redis.Set(key, "", time.Second)
  5022. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5023. redis.Set(keyOne, "", time.Second)
  5024. defer redis.Close()
  5025. if createErr != nil {
  5026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5027. return
  5028. }
  5029. c.ServeSuccessJSON(map[string]interface{}{
  5030. "msg": "ok",
  5031. "advices": newAdvices,
  5032. })
  5033. return
  5034. } else if is_child == 2 {
  5035. patient, _ := c.GetInt64("id", 0)
  5036. if patient <= 0 {
  5037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5038. return
  5039. }
  5040. adminUserInfo := c.GetMobileAdminUserInfo()
  5041. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  5042. if patientInfo.ID == 0 {
  5043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5044. return
  5045. }
  5046. var advice models.DoctorAdvice
  5047. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  5048. if code > 0 {
  5049. c.ServeFailJSONWithSGJErrorCode(code)
  5050. return
  5051. }
  5052. if advice.ParentId > 0 {
  5053. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  5054. if old.ID == 0 || old.PatientId != patient {
  5055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  5056. return
  5057. }
  5058. if old.StopState == 1 || old.ExecutionState == 1 {
  5059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  5060. return
  5061. }
  5062. if old.ParentId > 0 {
  5063. advice.ParentId = old.ParentId
  5064. }
  5065. advice.StartTime = old.StartTime
  5066. advice.AdviceDoctor = old.AdviceDoctor
  5067. advice.DeliveryWay = old.DeliveryWay
  5068. advice.ExecutionFrequency = old.ExecutionFrequency
  5069. advice.GroupNo = old.GroupNo
  5070. }
  5071. advice.Status = 1
  5072. advice.CreatedTime = time.Now().Unix()
  5073. advice.UpdatedTime = time.Now().Unix()
  5074. advice.StopState = 2
  5075. advice.ExecutionState = 2
  5076. advice.UserOrgId = adminUserInfo.Org.Id
  5077. advice.PatientId = patient
  5078. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5079. advice.IsSettle = 2
  5080. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  5081. if advice.PrescribingNumber == 0 {
  5082. advice.PrescribingNumber = 1
  5083. }
  5084. //查询该患者今日有没有双人核对
  5085. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  5086. if check.ID > 0 {
  5087. advice.Checker = check.Modifier
  5088. advice.CheckState = 1
  5089. advice.CheckTime = time.Now().Unix()
  5090. }
  5091. }
  5092. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5093. if infor.ID > 0 {
  5094. var cha_time int64
  5095. timeNowStr := time.Now().Format("2006-01-02")
  5096. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5097. //今日的日期减去设置的日期
  5098. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5099. if cha_time >= advice.RecordDate {
  5100. //查询审核是否允许
  5101. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id, 4)
  5102. //申请状态不允许的情况 拒绝修改
  5103. if infor.ApplicationStatus != 1 {
  5104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5105. return
  5106. }
  5107. }
  5108. }
  5109. err := service.CreateDoctorAdvice(&advice)
  5110. //记录日志
  5111. byterequest, _ := json.Marshal(advice)
  5112. adviceLog := models.XtDoctorAdviceLog{
  5113. UserOrgId: advice.UserOrgId,
  5114. PatientId: advice.PatientId,
  5115. AdminUserId: adminUserInfo.Org.Id,
  5116. Module: 1,
  5117. ErrLog: string(byterequest),
  5118. Status: 1,
  5119. Ctime: time.Now().Unix(),
  5120. Mtime: 0,
  5121. Source: "手机端新增医嘱",
  5122. RecordDate: advice.AdviceDate,
  5123. }
  5124. service.CreateDoctorAdviceLog(adviceLog)
  5125. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5126. redis := service.RedisClient()
  5127. //清空key 值
  5128. redis.Set(key, "", time.Second)
  5129. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5130. redis.Set(keyOne, "", time.Second)
  5131. defer redis.Close()
  5132. if err != nil {
  5133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5134. return
  5135. }
  5136. c.ServeSuccessJSON(map[string]interface{}{
  5137. "msg": "ok",
  5138. "advice": advice,
  5139. })
  5140. return
  5141. }
  5142. }
  5143. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  5144. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  5145. utils.ErrorLog("advice_name")
  5146. return enums.ErrorCodeParamWrong
  5147. }
  5148. adviceName, _ := json["advice_name"].(string)
  5149. if len(adviceName) == 0 {
  5150. utils.ErrorLog("len(advice_name) == 0")
  5151. return enums.ErrorCodeParamWrong
  5152. }
  5153. advice.AdviceName = adviceName
  5154. adviceDesc, _ := json["advice_desc"].(string)
  5155. advice.AdviceDesc = adviceDesc
  5156. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5157. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5158. advice.DrugSpec = drugSpec
  5159. }
  5160. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5161. remark, _ := json["remark"].(string)
  5162. advice.Remark = remark
  5163. }
  5164. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  5165. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  5166. // advice.Way = src_type
  5167. //}
  5168. if json["way"] == nil {
  5169. advice.Way = 0
  5170. } else {
  5171. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  5172. way := int64(json["way"].(float64))
  5173. advice.Way = way
  5174. }
  5175. }
  5176. if json["drug_id"] == nil {
  5177. advice.DrugId = 0
  5178. } else {
  5179. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  5180. drug_id := int64(json["drug_id"].(float64))
  5181. advice.DrugId = drug_id
  5182. }
  5183. }
  5184. if json["drug_name_id"] == nil {
  5185. advice.DrugNameId = 0
  5186. } else {
  5187. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  5188. drug_name_id := int64(json["drug_name_id"].(float64))
  5189. advice.DrugNameId = drug_name_id
  5190. }
  5191. }
  5192. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  5193. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  5194. advice.DrugSpecUnit = drugSpecUnit
  5195. }
  5196. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5197. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5198. advice.SingleDose = singleDose
  5199. }
  5200. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5201. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5202. advice.SingleDoseUnit = singleDoseUnit
  5203. }
  5204. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5205. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5206. advice.PrescribingNumber = prescribingNumber
  5207. }
  5208. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5209. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5210. advice.PrescribingNumberUnit = prescribingNumberUnit
  5211. }
  5212. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5213. deliveryWay, _ := json["delivery_way"].(string)
  5214. advice.DeliveryWay = deliveryWay
  5215. }
  5216. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5217. executionFrequency, _ := json["execution_frequency"].(string)
  5218. advice.ExecutionFrequency = executionFrequency
  5219. }
  5220. return 0
  5221. }
  5222. func (c *PatientApiController) DelDoctorAdvice() {
  5223. groupno, _ := c.GetInt64("groupno", -1)
  5224. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  5225. patient_id, _ := c.GetInt64("patient_id")
  5226. doc_advice_date, _ := c.GetInt64("advice_date")
  5227. redis := service.RedisClient()
  5228. if is_sub == 1 { //是
  5229. advice_id, _ := c.GetInt64("advice_id")
  5230. adminUserInfo := c.GetMobileAdminUserInfo()
  5231. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  5232. if advice.ID == 0 {
  5233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5234. return
  5235. }
  5236. advice.Status = 0
  5237. advice.UpdatedTime = time.Now().Unix()
  5238. advice.Modifier = adminUserInfo.AdminUser.Id
  5239. // 查询信息规挡的设置天数
  5240. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5241. if infor.ID > 0 && infor.WeekDay > 0 {
  5242. var cha_time int64
  5243. timeNowStr := time.Now().Format("2006-01-02")
  5244. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5245. //今日的日期减去设置的日期
  5246. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5247. if cha_time >= advice.AdviceDate {
  5248. //查询审核是否允许
  5249. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5250. //申请状态不允许的情况 拒绝修改
  5251. if infor.ApplicationStatus != 1 {
  5252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5253. return
  5254. }
  5255. }
  5256. }
  5257. //自备药
  5258. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5259. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5260. //查询库存是否是自备药
  5261. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  5262. if selfBasedrug.IsSelfDrug == 1 {
  5263. creater := adminUserInfo.AdminUser.Id
  5264. //退库
  5265. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  5266. }
  5267. }
  5268. err := service.DeleteDoctorAdvice(&advice)
  5269. //记录日志
  5270. byterequest, _ := json.Marshal(advice)
  5271. adviceLog := models.XtDoctorAdviceLog{
  5272. UserOrgId: advice.UserOrgId,
  5273. PatientId: advice.PatientId,
  5274. AdminUserId: adminUserInfo.AdminUser.Id,
  5275. Module: 4,
  5276. ErrLog: string(byterequest),
  5277. Status: 1,
  5278. Ctime: time.Now().Unix(),
  5279. Mtime: 0,
  5280. Source: "手机端删除医嘱",
  5281. RecordDate: advice.RecordDate,
  5282. }
  5283. service.CreateDoctorAdviceLog(adviceLog)
  5284. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5285. redis.Set(key, "", time.Second)
  5286. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5287. redis.Set(keyTwo, "", time.Second)
  5288. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5289. redis.Set(keyThree, "", time.Second)
  5290. redis.Close()
  5291. if err != nil {
  5292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5293. return
  5294. }
  5295. c.ServeSuccessJSON(map[string]interface{}{
  5296. "msg": "ok",
  5297. })
  5298. return
  5299. } else { //
  5300. var ids []string
  5301. if groupno == 0 {
  5302. advice_id := c.GetString("advice_id")
  5303. ids = strings.Split(advice_id, ",")
  5304. if len(ids) <= 0 {
  5305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5306. return
  5307. }
  5308. }
  5309. if groupno < 0 {
  5310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5311. return
  5312. }
  5313. adminUserInfo := c.GetMobileAdminUserInfo()
  5314. var advice models.DoctorAdvice
  5315. if groupno > 0 {
  5316. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  5317. if advice.ID == 0 {
  5318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5319. return
  5320. }
  5321. } else {
  5322. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  5323. for _, item := range advices {
  5324. if item.ID == 0 {
  5325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5326. return
  5327. }
  5328. }
  5329. }
  5330. advice.UpdatedTime = time.Now().Unix()
  5331. advice.Status = 0
  5332. advice.GroupNo = groupno
  5333. advice.Modifier = adminUserInfo.AdminUser.Id
  5334. var err error
  5335. if groupno > 0 {
  5336. // 查询信息规挡的设置天数
  5337. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5338. if infor.ID > 0 {
  5339. var cha_time int64
  5340. timeNowStr := time.Now().Format("2006-01-02")
  5341. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5342. //今日的日期减去设置的日期
  5343. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5344. if cha_time >= advice.AdviceDate {
  5345. //查询审核是否允许
  5346. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5347. //申请状态不允许的情况 拒绝修改
  5348. if infor.ApplicationStatus != 1 {
  5349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5350. return
  5351. }
  5352. }
  5353. }
  5354. //自备药
  5355. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5356. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5357. //查询库存是否是自备药
  5358. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  5359. if selfBasedrug.IsSelfDrug == 1 {
  5360. creater := adminUserInfo.AdminUser.Id
  5361. //退库
  5362. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  5363. }
  5364. }
  5365. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  5366. //记录日志
  5367. byterequest, _ := json.Marshal(advice)
  5368. adviceLog := models.XtDoctorAdviceLog{
  5369. UserOrgId: advice.UserOrgId,
  5370. PatientId: advice.PatientId,
  5371. AdminUserId: adminUserInfo.AdminUser.Id,
  5372. Module: 4,
  5373. ErrLog: string(byterequest),
  5374. Status: 1,
  5375. Ctime: time.Now().Unix(),
  5376. Mtime: 0,
  5377. Source: "手机端删除医嘱",
  5378. RecordDate: advice.RecordDate,
  5379. }
  5380. service.CreateDoctorAdviceLog(adviceLog)
  5381. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5382. redis.Set(key, "", time.Second)
  5383. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5384. redis.Set(keyTwo, "", time.Second)
  5385. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5386. redis.Set(keyThree, "", time.Second)
  5387. } else {
  5388. // 查询信息规挡的设置天数
  5389. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5390. if infor.ID > 0 {
  5391. var cha_time int64
  5392. timeNowStr := time.Now().Format("2006-01-02")
  5393. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5394. //今日的日期减去设置的日期
  5395. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5396. if cha_time >= advice.AdviceDate {
  5397. //查询审核是否允许
  5398. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5399. //申请状态不允许的情况 拒绝修改
  5400. if infor.ApplicationStatus != 1 {
  5401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5402. return
  5403. }
  5404. }
  5405. }
  5406. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  5407. advicelist, _ := service.GetBatchDoctorAdviceList(ids, adminUserInfo.Org.Id)
  5408. for _, item := range advicelist {
  5409. //自备药
  5410. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5411. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5412. //查询库存是否是自备药
  5413. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(item.DrugId, item.UserOrgId)
  5414. if selfBasedrug.IsSelfDrug == 1 {
  5415. creater := adminUserInfo.AdminUser.Id
  5416. //退库
  5417. service.SelfDrugAutoAddCancelInfoOne(item, creater)
  5418. }
  5419. }
  5420. //记录日志
  5421. byterequest, _ := json.Marshal(item)
  5422. adviceLog := models.XtDoctorAdviceLog{
  5423. UserOrgId: item.UserOrgId,
  5424. PatientId: item.PatientId,
  5425. AdminUserId: adminUserInfo.AdminUser.Id,
  5426. Module: 4,
  5427. ErrLog: string(byterequest),
  5428. Status: 1,
  5429. Ctime: time.Now().Unix(),
  5430. Mtime: 0,
  5431. Source: "手机端批量删除医嘱",
  5432. RecordDate: item.RecordDate,
  5433. }
  5434. service.CreateDoctorAdviceLog(adviceLog)
  5435. }
  5436. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5437. redis.Set(key, "", time.Second)
  5438. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5439. redis.Set(keyTwo, "", time.Second)
  5440. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5441. redis.Set(keyThree, "", time.Second)
  5442. redis.Close()
  5443. }
  5444. if err != nil {
  5445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5446. return
  5447. }
  5448. c.ServeSuccessJSON(map[string]interface{}{
  5449. "msg": "ok",
  5450. })
  5451. return
  5452. }
  5453. }
  5454. // /m/api/advice/group/modify_starttime [post]
  5455. // @param group_no:int
  5456. // @param start_time:string yyyy-MM-dd hh:mm:ss
  5457. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  5458. group_no, _ := this.GetInt64("group_no")
  5459. start_time_str := this.GetString("start_time")
  5460. if group_no <= 0 || len(start_time_str) == 0 {
  5461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5462. return
  5463. }
  5464. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  5465. if parseTimeErr != nil {
  5466. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  5467. return
  5468. }
  5469. adminUserInfo := this.GetMobileAdminUserInfo()
  5470. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  5471. if updateStartTimeErr != nil {
  5472. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  5473. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5474. return
  5475. }
  5476. this.ServeSuccessJSON(map[string]interface{}{
  5477. "start_time": startTime.Unix(),
  5478. })
  5479. }
  5480. func (this *PatientApiController) DelSubDoctorAdvice() {
  5481. advice_id, _ := this.GetInt64("advice_id")
  5482. adminUserInfo := this.GetMobileAdminUserInfo()
  5483. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  5484. if advice.ID == 0 {
  5485. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5486. return
  5487. }
  5488. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  5489. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  5490. // return
  5491. //}
  5492. advice.Status = 0
  5493. advice.UpdatedTime = time.Now().Unix()
  5494. advice.Modifier = adminUserInfo.AdminUser.Id
  5495. err := service.DeleteDoctorAdvice(&advice)
  5496. if err != nil {
  5497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5498. return
  5499. }
  5500. this.ServeSuccessJSON(map[string]interface{}{
  5501. "msg": "ok",
  5502. })
  5503. return
  5504. }
  5505. func (this *PatientApiController) GetAdviceUnReadMessage() {
  5506. //adminUserInfo := this.GetMobileAdminUserInfo()
  5507. //service.FindUnReadDoctorAdviceMessage()
  5508. }
  5509. func (this *PatientApiController) GetPatientsByKeyWord() {
  5510. keyWord := this.GetString("keyword")
  5511. adminUserInfo := this.GetMobileAdminUserInfo()
  5512. today := utils.ZeroHourTimeOfDay(time.Now())
  5513. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  5514. if err != nil {
  5515. utils.ErrorLog(err.Error())
  5516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5517. return
  5518. }
  5519. this.ServeSuccessJSON(map[string]interface{}{
  5520. "patient": patient,
  5521. })
  5522. }
  5523. func (this *PatientApiController) GetSearchPatient() {
  5524. keyWord := this.GetString("keyword")
  5525. adminUserInfo := this.GetMobileAdminUserInfo()
  5526. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  5527. if err != nil {
  5528. utils.ErrorLog(err.Error())
  5529. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5530. return
  5531. }
  5532. this.ServeSuccessJSON(map[string]interface{}{
  5533. "patient": patient,
  5534. })
  5535. }
  5536. func (c *PatientApiController) ExecProject() {
  5537. execution_time := c.GetString("execution_time")
  5538. project_id, _ := c.GetInt64("project_id")
  5539. team_id, _ := c.GetInt64("team_id")
  5540. is_check_team, _ := c.GetInt64("is_check_team")
  5541. if len(execution_time) <= 0 {
  5542. utils.ErrorLog("execution_time")
  5543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5544. return
  5545. }
  5546. timeLayout2 := "2006-01-02 15:04:05"
  5547. loc, _ := time.LoadLocation("Local")
  5548. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  5549. if errs != nil {
  5550. utils.ErrorLog(errs.Error())
  5551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5552. return
  5553. }
  5554. adminInfo := c.GetMobileAdminUserInfo()
  5555. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5556. //针对舒和
  5557. if adminInfo.Org.Id == 10644 {
  5558. if project.StartTime > theTime.Unix() {
  5559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  5560. return
  5561. }
  5562. }
  5563. if project.Type == 3 {
  5564. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  5565. if good.IsUser != 1 {
  5566. //查询开关是否开启
  5567. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  5568. //开关已经开启
  5569. if stockSetting.IsType == 1 {
  5570. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  5571. scheduleDateStart := theTime.Format("2006-01-02")
  5572. timeLayout3 := "2006-01-02"
  5573. loc, _ := time.LoadLocation("Local")
  5574. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  5575. //查询该耗材是否已经出库
  5576. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  5577. if auto.ID == 0 {
  5578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  5579. return
  5580. }
  5581. }
  5582. }
  5583. if good.IsUser == 1 && good.IsWarehouse == 1 {
  5584. //查询开关是否开启
  5585. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  5586. //开关已经开启
  5587. if stockSetting.IsType == 1 {
  5588. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  5589. scheduleDateStart := theTime.Format("2006-01-02")
  5590. timeLayout3 := "2006-01-02"
  5591. loc, _ := time.LoadLocation("Local")
  5592. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  5593. //查询该耗材是否已经出库
  5594. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  5595. if auto.ID == 0 {
  5596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  5597. return
  5598. }
  5599. }
  5600. }
  5601. }
  5602. if project.ExecutionState == 1 {
  5603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  5604. return
  5605. }
  5606. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  5607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5608. return
  5609. }
  5610. project.ExecutionState = 1
  5611. project.ExecutionStaff = adminInfo.AdminUser.Id
  5612. project.ExecutionTime = theTime.Unix()
  5613. if team_id == 0 {
  5614. // 查询信息规挡的设置天数
  5615. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5616. if infor.ID > 0 {
  5617. var cha_time int64
  5618. timeNowStr := time.Now().Format("2006-01-02")
  5619. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5620. //今日的日期减去设置的日期
  5621. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5622. if cha_time >= project.RecordDate {
  5623. //查询审核是否允许
  5624. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5625. //申请状态不允许的情况 拒绝修改
  5626. if infor.ApplicationStatus != 1 {
  5627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5628. return
  5629. }
  5630. }
  5631. }
  5632. err := service.SaveHisProject(&project)
  5633. if err == nil {
  5634. c.ServeSuccessJSON(map[string]interface{}{
  5635. "project": project,
  5636. })
  5637. } else {
  5638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5639. return
  5640. }
  5641. } else {
  5642. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5643. // 查询信息规挡的设置天数
  5644. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5645. if infor.ID > 0 {
  5646. var cha_time int64
  5647. timeNowStr := time.Now().Format("2006-01-02")
  5648. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5649. //今日的日期减去设置的日期
  5650. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5651. if cha_time >= project.RecordDate {
  5652. //查询审核是否允许
  5653. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5654. //申请状态不允许的情况 拒绝修改
  5655. if infor.ApplicationStatus != 1 {
  5656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5657. return
  5658. }
  5659. }
  5660. }
  5661. err := service.SaveHisProject(&project)
  5662. if err == nil {
  5663. c.ServeSuccessJSON(map[string]interface{}{
  5664. "project": project,
  5665. })
  5666. } else {
  5667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5668. return
  5669. }
  5670. } else {
  5671. // 查询信息规挡的设置天数
  5672. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5673. if infor.ID > 0 {
  5674. var cha_time int64
  5675. timeNowStr := time.Now().Format("2006-01-02")
  5676. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5677. //今日的日期减去设置的日期
  5678. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5679. if cha_time >= project.RecordDate {
  5680. //查询审核是否允许
  5681. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5682. //申请状态不允许的情况 拒绝修改
  5683. if infor.ApplicationStatus != 1 {
  5684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5685. return
  5686. }
  5687. }
  5688. }
  5689. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5690. var ids []int64
  5691. for _, items := range ps {
  5692. ids = append(ids, items.ID)
  5693. }
  5694. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  5695. if err == nil {
  5696. c.ServeSuccessJSON(map[string]interface{}{
  5697. "project": project,
  5698. })
  5699. } else {
  5700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5701. return
  5702. }
  5703. }
  5704. }
  5705. }
  5706. func (c *PatientApiController) CheckProject() {
  5707. adminInfo := c.GetMobileAdminUserInfo()
  5708. project_id, _ := c.GetInt64("project_id")
  5709. team_id, _ := c.GetInt64("team_id")
  5710. is_check_team, _ := c.GetInt64("is_check_team")
  5711. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5712. if project.CheckState == 1 {
  5713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  5714. return
  5715. }
  5716. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  5717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5718. return
  5719. }
  5720. project.Checker = adminInfo.AdminUser.Id
  5721. project.CheckTime = time.Now().Unix()
  5722. project.CheckState = 1
  5723. if team_id == 0 {
  5724. // 查询信息规挡的设置天数
  5725. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5726. if infor.ID > 0 {
  5727. var cha_time int64
  5728. timeNowStr := time.Now().Format("2006-01-02")
  5729. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5730. //今日的日期减去设置的日期
  5731. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5732. if cha_time >= project.RecordDate {
  5733. //查询审核是否允许
  5734. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5735. //申请状态不允许的情况 拒绝修改
  5736. if infor.ApplicationStatus != 1 {
  5737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5738. return
  5739. }
  5740. }
  5741. }
  5742. err := service.SaveHisProject(&project)
  5743. if err == nil {
  5744. c.ServeSuccessJSON(map[string]interface{}{
  5745. "msg": "ok",
  5746. "project": project,
  5747. })
  5748. } else {
  5749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5750. return
  5751. }
  5752. } else {
  5753. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5754. // 查询信息规挡的设置天数
  5755. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5756. if infor.ID > 0 {
  5757. var cha_time int64
  5758. timeNowStr := time.Now().Format("2006-01-02")
  5759. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5760. //今日的日期减去设置的日期
  5761. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5762. if cha_time >= project.RecordDate {
  5763. //查询审核是否允许
  5764. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5765. //申请状态不允许的情况 拒绝修改
  5766. if infor.ApplicationStatus != 1 {
  5767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5768. return
  5769. }
  5770. }
  5771. }
  5772. err := service.SaveHisProject(&project)
  5773. if err == nil {
  5774. c.ServeSuccessJSON(map[string]interface{}{
  5775. "msg": "ok",
  5776. "project": project,
  5777. })
  5778. } else {
  5779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5780. return
  5781. }
  5782. } else {
  5783. // 查询信息规挡的设置天数
  5784. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5785. if infor.ID > 0 {
  5786. var cha_time int64
  5787. timeNowStr := time.Now().Format("2006-01-02")
  5788. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5789. //今日的日期减去设置的日期
  5790. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5791. if cha_time >= project.RecordDate {
  5792. //查询审核是否允许
  5793. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5794. //申请状态不允许的情况 拒绝修改
  5795. if infor.ApplicationStatus != 1 {
  5796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5797. return
  5798. }
  5799. }
  5800. }
  5801. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5802. var ids []int64
  5803. for _, items := range ps {
  5804. ids = append(ids, items.ID)
  5805. }
  5806. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  5807. if err == nil {
  5808. c.ServeSuccessJSON(map[string]interface{}{
  5809. "project": project,
  5810. })
  5811. } else {
  5812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5813. return
  5814. }
  5815. }
  5816. }
  5817. }