patient_api_controller.go 240KB

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